Jump to content

Recommended Posts

Posted

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.


Posted

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"

:)

Posted
Mhz, I often wonder if scout the forums for AutoIt threads. You always give the best, and most expedient, reponses. :P

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.

:)

@bigbroantonio

You 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 & '\')

;)

Posted

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

Posted
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. ;)

Posted
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

Oh, 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. ;)

Posted

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"
Next

You wouldn't believe it but it took me several hours to figure this one out :P Oh yea, actually that code up there detects which drive, but it also sets a variable for the directory \OEM on the CD.

Posted
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"
Next

You wouldn't believe it but it took me several hours to figure this one out :P 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
EndIf
EndFunc

More examples of DriveGetDrive() are available if searched. :rolleyes:

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...