Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546

    Need help with naming "Relative Path"

    Can anyone tell me the best way to rename the following "absolute pathway" as a "relative path"?

    The pathway is:
    C:\\Documents and Settings\\JohnSmith\\Cookies\\JohnSmith@mywebsite. txt

    I am using File.Delete to delete the "JohnSmith@mywebsite.txt" cookie-file. This command works successfully providing I use the "absolute pathway" mentioned above ... BUT I need to rename it as "relative" pathway so the file will still get deleted, regardless of which computer my app is used on, and regardless of the drive on which Windows is installed, etc ...

    I was thinking of something like:

    "%systemdrive%\\Documents and Settings\\%userName%\\Cookies\\*@mywebsite.txt"

    Is this the best way to do it? Or is there a more "foolproof" way to do it? Please, any suggestions welcome!

  2. #2
    Join Date
    Jul 2007
    Posts
    158
    There you go

    Code:
    path = String.Left(String.SplitPath(_TempFolder).Folder, String.Length(String.SplitPath(_TempFolder).Folder)-9).."Cookies\\";
    File.Open(path, "", SW_SHOWNORMAL);

  3. #3
    Join Date
    Jul 2007
    Posts
    158
    That was silly, I missed drive part, but this will be the easier

    Code:
    path = String.SplitPath(_DesktopFolder).Drive..String.SplitPath(_DesktopFolder).Folder.."Cookies\\";
    File.Open(path, "", SW_SHOWNORMAL);

  4. #4
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546
    arb,

    Thanks ... but I don't understand this. The code you provided seems to find the Cookies folder okay ... but I can't see how to modify your code, so that it deletes specific cookie-files. The code as is, just opens the Cookies folder.

    As I can't understand the logic behind the command, I'm having a hard time modifying it. Could you perhaps provide a full-example? Let's pretend that there is a cookie-file named "abc.txt". Could you provide the full code, so that this file would be deleted?

    PS.
    Also, could you tell me if this code will successfully find the Cookies folder on Windows '98/ME machines? (The reason I ask is because Windows-XP uses a different pathway than Windows-98/ME to the Cookies folder).

  5. #5
    Join Date
    Jul 2007
    Posts
    158
    Quote Originally Posted by mystica View Post
    The code as is, just opens the Cookies folder.
    I just want to show you that the code is working for getting the path.

    Quote Originally Posted by mystica View Post
    Let's pretend that there is a cookie-file named "abc.txt". Could you provide the full code, so that this file would be deleted?
    OK, you can delete the abc.txt file like this:

    Code:
    path = String.SplitPath(_DesktopFolder).Drive..String.SplitPath(_DesktopFolder).Folder.."Cookies\\";
    File.Delete(path.."abc.txt", false, false, false, nil);
    or this:

    Code:
    File.Delete(String.SplitPath(_DesktopFolder).Drive..String.SplitPath(_DesktopFolder).Folder.."Cookies\\abc.txt", false, false, false, nil);
    And I'm not sure about Windows-98/ME, cos I don't have it, but you can try it on those operating systems.

  6. #6
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546
    Hey, thanks arb ... that's great! I just tried it out and everything works beautifully. (I'm yet to try it out on a Win98/ME machine ... but works like a charm on XP). So, your help is much appreciated.

    In the interests of learning, I was hoping you might extend your patience a little further, in an effort to help me understand the actual "logic" of your code. What I mean is, I don't really understand:

    "(String.SplitPath(_DesktopFolder)"

    What's actually happening there? This part has me mystified???

  7. #7
    Join Date
    Aug 2004
    Location
    Somewhere in Texas, USA
    Posts
    417
    Or you could do it this way.


    Code:
    File.Delete(os.getenv("USERPROFILE").."\\Cookies\\abc.txt", false, false, false, nil);
    It gets the current logged on users "Documents and Settings" folder environment variable.

  8. #8
    Join Date
    Jul 2007
    Posts
    158
    Quote Originally Posted by mystica View Post
    "(String.SplitPath(_DesktopFolder)"
    What's actually happening there? This part has me mystified???
    This (_DesktopFolder) will pass you the address of user desktop, like this:

    "C:\Documents and Settings\User\Desktop"

    Then I splith it to these strings:

    .Drive = "C:\"
    .Folder = "\Documents and Settings\User\"
    .Filename = "Desktop"

    And concat .Drive with .Folder, So now I have this:
    "C:\Documents and Settings\User\"

    and I can concat it with "Cookies" folder

    Quote Originally Posted by mwreyf1 View Post
    os.getenv("USERPROFILE")
    That was new, thankQ mwreyf1

  9. #9
    Join Date
    Aug 2004
    Location
    Somewhere in Texas, USA
    Posts
    417
    Glad to contribute arb.

    Found that in the lua.org manual

    I have gotten in the habit of searching through http://www.lua.org/manual/5.1/ when I can't get it done with a APMS action.

    Saved my butt a few times now.

    Keep in mind that code can be used with anything that you would get back from opening a DOS window (cmd.exe) and typing SET and <Enter> at the prompt.

  10. #10
    Join Date
    Jul 2007
    Posts
    158
    I forced my self Thousand times to read the refrence manual, but there is not enough time to do this.

    but i'll do this soon

    Thanks again

  11. #11
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546
    mwreyf1 & arb,

    A huge thanks to the both of you for helping me out on this issue. The assistance is much appreciated. Cheers for elaborating on your code, arb ... and thanks mwreyf1 for the alternative (I'll have a look at that lua.org manual myself).

Similar Threads

  1. Button Naming Convention
    By DwayneMc in forum Autorun MAX! 2.1 Suggestions
    Replies: 1
    Last Post: 11-02-2007, 08:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts