View Full Version : Need help with naming "Relative Path"
mystica
07-09-2008, 02:43 AM
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!
There you go :D
path = String.Left(String.SplitPath(_TempFolder).Folder, String.Length(String.SplitPath(_TempFolder).Folder )-9).."Cookies\\";
File.Open(path, "", SW_SHOWNORMAL);
That was silly, I missed drive part, but this will be the easier
path = String.SplitPath(_DesktopFolder).Drive..String.Spl itPath(_DesktopFolder).Folder.."Cookies\\";
File.Open(path, "", SW_SHOWNORMAL);
mystica
07-10-2008, 02:39 AM
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).
The code as is, just opens the Cookies folder.
I just want to show you that the code is working for getting the path.
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:
path = String.SplitPath(_DesktopFolder).Drive..String.Spl itPath(_DesktopFolder).Folder.."Cookies\\";
File.Delete(path.."abc.txt", false, false, false, nil);
or this:
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.
mystica
07-10-2008, 04:32 AM
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???
mwreyf1
07-10-2008, 08:22 AM
Or you could do it this way.
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.
"(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
os.getenv("USERPROFILE")
That was new, thankQ mwreyf1
mwreyf1
07-11-2008, 11:52 PM
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.
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
mystica
07-12-2008, 02:11 AM
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).
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.