SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 7 of 7
  1. #1
    Member
    Join Date
    Nov 2004
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    User-specific file paths

    In my application, there is functionality that only happens once - right after fresh install.

    The proper way to test this is to uninstall the app then reinstall.


    The quick and dirty way is to delete a couple .ini files which tricks the app into firing the first-run functionality.

    This little bit of code works fine:
    strFileSpec = "C:\Documents and Settings\UserName\file.ini"
    If fso.fileexists (strFileSpec) Then
    fso.deletefile (strFileSpec)
    End If

    The problem is, those .ini files are in C:\Documents and Settings\UserName\file.ini and the UserName is different for each machine on we wish to run this test.

    x= Environment.Value("UserName") will get me the username as it was entered when logging into the machine/network but in some cases this login username is different than the UserName in that file path.

    How can I get the filepath UserName for this to work?

    Thanks in advance,

    Blake

  2. #2
    Senior Member
    Join Date
    Oct 2004
    Location
    Bangalore
    Posts
    270
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: User-specific file paths

    Hi,
    there are many help files where in can get the path of the file..if u give the filename...use this it may help u out...right now i am bit busy..if u want the code i can send it next time...
    sorry for that...

  3. #3
    Member
    Join Date
    Nov 2004
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: User-specific file paths

    I probably did not express myself well. The problem is, I don't know in advance what the filepath is going to be so I need a way to find out.

    Yes, I see the Path property in the help file.

    The entire description of this property is "Returns the path for a specified file, folder, or drive." which on the face of it, sounds like exactly what I need.

    I pasted the function provided in the help file into a blank script then wrote a statement to call this function, using a .doc file I have saved on my desktop.

    I tried this:

    varMyPath = ShowFileAccessInfo("QTPro backup.doc")

    msgbox "This is the path: <" & varMyPath & "> "

    [[function pasted here]]

    But it gives me an error "File Not Found".

    So my assumption is that the Path property needs more to go on than I provided it in this simple script. When I change the function call to inlude the entire path C:\Documents and Settings\bwalter\Desktop\QTPro backup.doc

    I get it to work.

    Which is surprisingly useless because I had to input the filepath in order to return the filepath.

    How can I get the filepath without knowing it in advance? What am I missing?

    Thanks again,

    Blake

  4. #4
    Senior Member
    Join Date
    Apr 2001
    Posts
    210
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: User-specific file paths

    Hi Blake,
    The problem is, I don't know in advance what the filepath is going to be so I need a way to find out
    <font size="2" face="Verdana, Arial, Helvetica">This function returns path for all files with the given name found under the given folder. The function is recursive and it searches all the subfolders of the given folder. If you need only the first file you can stop the recursion when the first occurence found.
    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">Function FindFiles(StartFolder, FileName)
    Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot
    Set f = fso.GetFolder(StartFolder)
    Set fls = f.Files
    For Each f1 In fls
    If f1.Name = FileName Then
    FindFiles = FindFiles &amp; f1.Path &amp; vbNewLine
    End If
    Next
    Set sf = f.SubFolders
    For Each fldr In sf
    FindFiles = FindFiles &amp; FindFiles(fldr.Path, FileName)
    Next
    End Function</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">Sample usage:
    fls = FindFiles("C:\Documents and Settings", "YouFileName.ini")
    msgbox fls


    Thanks,
    -Dima.
    -Dima

  5. #5
    Member
    Join Date
    Dec 2004
    Location
    Earth
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: User-specific file paths

    You can make an API call to get the username of the current windows user.

  6. #6
    Member
    Join Date
    Nov 2004
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: User-specific file paths

    Thanks -Dima, that was just what I needed. A little tweaking and that lovely function has saved the day.

    As for creating API calls, I know virtually nothing about this. Can someone point me in the direction of a good educational resource (book, web, whatever) where I can self-learn API?

    Incidentally, wouldn't the API call return the same information as x = Environment("UserName") (which I cannot use because in many cases the UserName is different than the file path - in my case my username is "bwalke1" and the filepath is C:\Documents and Settings\bwalter\ ).

    Thanks,

    Blake

  7. #7
    Member
    Join Date
    Aug 2004
    Location
    India
    Posts
    53
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: User-specific file paths

    Hi,

    You can get help on advance vbscripting from this site..

    http://www.microsoft.com/technet/scr...s/default.mspx

    Also download VBSEdit from www.adersoft.com, it has some system script samples which will help you to get the system information.

    Regards,
    Unmesh Gundecha

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 9.38%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 11:48 AM.

Copyright BetaSoft Inc.