bigbroantonio Posted January 25, 2006 Posted January 25, 2006 I'd like to copy files and dirs from a cd to various point of the hard drive. The problem is that I won't always be using drive D: or E: or whatever. So I'd like the script in some way to work out where it's running from and then copy the files from there (so if it's running on drive E: it will copy from there)Things like FileCopy("setup\file.exe","C:\windows\system32\")just don't work. Even is the dir "setup" is there it seems to need a real path to the file/dir.Thanks.
MHz Posted January 26, 2006 Posted January 26, 2006 Sounds to me that the Working Directory is not the Script Directory, so your relative paths are failing.When working relatively, you should check your Working Directory first before using the relative paths. FileChangeDir() can set your Working Directory.As below, the script checks if the Working Directory is different to Script Directory, and if it is, then change Working Directory to the Script Directory.If @WorkingDir <> @ScriptDir Then FileChangeDir(@ScriptDir)FileCopy("setup\file.exe","C:\windows\system32\")Or you can simply use the @ScriptDir macro. This is the fullpath to the script as shown below.FileCopy(@ScriptDir & "\setup\file.exe","C:\windows\system32\")If @ScriptDir is "E:\folder" then the 1st parameter would evaluate to "E:\folder\setup\file.exe"
Dumpy Dooby Posted January 26, 2006 Posted January 26, 2006 Mhz, I often wonder if scout the forums for AutoIt threads. You always give the best, and most expedient, reponses.
MHz Posted January 26, 2006 Posted January 26, 2006 Mhz, I often wonder if scout the forums for AutoIt threads. You always give the best, and most expedient, reponses. Indeed scout is recommended, as I tire of giving the same good responses over and over. Thanks, I will accept your last line as a nice compliment. @bigbroantonioYou should set your 2nd parameter with a macro as well. Just incase the path can be different for some reason.example:FileCopy(@ScriptDir & "\setup\file.exe", @SystemDir & '\')
bigbroantonio Posted January 28, 2006 Author Posted January 28, 2006 Thanks for your replies, MHz.I'll check to it as soon as I can, and get back to you with my results.I didn't really understand the "scout the forums" bit. Do you mean searching in the forums. I did have a look before posting, but couldn't really find anything - or maybe I didn't look hard enough.Thanks again
MHz Posted January 29, 2006 Posted January 29, 2006 I didn't really understand the "scout the forums" bit. Do you mean searching in the forums. I did have a look before posting, but couldn't really find anything - or maybe I didn't look hard enough.Yeah, to scout is baxically to search, but that is fine. I do not believe that I or anyone else has explained the working directory to a meanful concept. I use the working directory and change directory often in scripts to make handling tasks easier.
Dumpy Dooby Posted January 29, 2006 Posted January 29, 2006 Thanks for your replies, MHz.I'll check to it as soon as I can, and get back to you with my results.I didn't really understand the "scout the forums" bit. Do you mean searching in the forums. I did have a look before posting, but couldn't really find anything - or maybe I didn't look hard enough.Thanks againOh, that wasn't directed at you. I was asking MHz if he searches the forum for AutoIt threads, since he always provides a swift and accurate response in the them.
RogueSpear Posted January 29, 2006 Posted January 29, 2006 I came up with this little snippet for detecting the drive with your Windows CD in it:For $drive = 65 to 90 If FileExists(chr($drive) & ":\WIN51IP.SP2") Then $OEM = chr($drive) & ":\OEM"NextYou wouldn't believe it but it took me several hours to figure this one out Oh yea, actually that code up there detects which drive, but it also sets a variable for the directory \OEM on the CD.
MHz Posted January 30, 2006 Posted January 30, 2006 I came up with this little snippet for detecting the drive with your Windows CD in it:For $drive = 65 to 90 If FileExists(chr($drive) & ":\WIN51IP.SP2") Then $OEM = chr($drive) & ":\OEM"NextYou wouldn't believe it but it took me several hours to figure this one out Oh yea, actually that code up there detects which drive, but it also sets a variable for the directory \OEM on the CD.AutoIt uses DriveGetDrive() to retrieve drive letters. Here is a User Defined Function that will provide the path to the $OEM$ folder on a CD in $variable.$variable = _Drive()MsgBox(0, 'Drive Letter', $variable)Func _Drive() $drive = DriveGetDrive('CDROM') If Not @error Then For $i = 1 To $drive[0] If FileExists($drive[$i] & '\WIN51IP.SP2') Then Return $drive[$i] & '\$OEM$' Next EndIfEndFuncMore examples of DriveGetDrive() are available if searched.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now