Jump to content

FileCopy help


Recommended Posts

Help! I am trying to copy a file that contains spaces within the name. Can someone give me some help. Thanks!

Code:

;Check for new Map TECONSOLE Drive.exe

$filename="Map TECONSOLE Drive.exe"

MapTEservercheck()

MapTElocalcheck()

Func MapTEservercheck()

If FileExists('Z:\Patches\' & $filename) Then

FileWriteLine($log, $timestamp & " Path and file are there.")

$serverFile=FileGetTime('Z:\Patches\' & $filename,0,1)

EndIf

EndFunc

Func MapTElocalcheck()

If FileExists('C:\batch\utils\' & $filename) Then

FileWriteLine($log, $timestamp & " local file there.")

$localFile=FileGetTime('C:\BATCH\utils\' & $filename,0,1)

MapTEcomparefiles()

Else

$err=FileCopy('Z:\Patches\' & $filename, 'C:\BATCH\utils\',1)

FileWriteLine($log, $timestamp & " MapTElocalcheck() $err is: " & $err)

EndIf

EndFunc

Func MapTEcomparefiles()

FileWriteLine($log, $timestamp & " $localfile is: " & $localfile)

FileWriteLine($log, $timestamp & " $serverfile is: " & $serverfile)

If $localFile <> $serverFile Then

FileWriteLine($log, $timestamp & " Files are different and copy server copy to local.")

$err=FileCopy('Z:\Patches\' & $filename, 'C:\BATCH\utils\',1)

FileWriteLine($log, $timestamp & " MapTEcomparefiles() $err is: " & $err)

Else

FileWriteLine($log, $timestamp & " Files are the same.")

EndIf

EndFunc

Link to comment
Share on other sites

What's the question? AutoIt doesn't have a problem with spaces in file names or paths. Entering a literal string requires quotes around it whether it has spaces or not.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Issue is that it isn't finding the file when it is there. How would I make see the file correctly.

$filename="Map TECONSOLE Drive.exe"

IF FileExists('Z:\Patches\' & $filename)

Help with the syntax please.

Link to comment
Share on other sites

Hmm. :)

That's just it. I use FileExists() in lots of scripts with files containing spaces in the name. It just works. I have heard of people having problems passing file names to DOS shells and the like, but not inside AutoIt itself. In those other situations, the most common fix is to use the 8.3 short names of the files:

$filename="Map TECONSOLE Drive.exe"
$ShortPath = FileGetShortName('Z:\Patches\' & $filename)
IF FileExists($ShortPath) Then
    ; ...
EndIf

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

OK, now I am getting to the point where I do the actual file copy.

$filename="Map TECONSOLE Drive.exe"

$SShortPath=FileGetShortName('Z:\Patches\' & $filename)

$SFullPath=FileGetLongName('Z:\Patches\' & $filename)

$LShortPath=FileGetShortName('C:\BATCH\utils\' & $filename)

$err=FileCopy($SFullPath, 'C:\BATCH\utils\',1)

FileWriteLine($log, $timestamp & " MapTEcomparefiles() $err is: " & $err)

Why is this giving me a 0 for $err?

Link to comment
Share on other sites

It could be the destination folder doesn't exist, or is read only.

Or, the file already exists and is read only.

Or, your path is not what you think it is.

And you ducked the question... put a line in there to log the resulting file path and see if it is really what you expected:

$RET=FileCopy('Z:\Patches\' & $filename, 'C:\BATCH\utils\',1)
FileWriteLine($log, $timestamp & "  Copied file from: Z:\Patches\" & $filename & "  to: C:\BATCH\utils\  --  Returned: " & $RET)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Added in your two lines exactly and ran exe. Here is output from the log file. The everything looks correct to me.

20070302 14:15:04 local Path and file are there.

20070302 14:15:04 Files are different and copy server copy to local.

20070302 14:15:04 The full path of the file is: Z:\Patches\Map TECONSOLE Drive.exe

20070302 14:15:04 Copied file from: Z:\Patches\Map TECONSOLE Drive.exe to: C:\BATCH\utils\ -- Returned: 0

Link to comment
Share on other sites

Added in your two lines exactly and ran exe. Here is output from the log file. The everything looks correct to me.

20070302 14:15:04 local Path and file are there.

20070302 14:15:04 Files are different and copy server copy to local.

20070302 14:15:04 The full path of the file is: Z:\Patches\Map TECONSOLE Drive.exe

20070302 14:15:04 Copied file from: Z:\Patches\Map TECONSOLE Drive.exe to: C:\BATCH\utils\ -- Returned: 0

And what happens if you just open a command line shell and do a simple copy manually:

xcopy "Z:\Patches\Map TECONSOLE Drive.exe"  C:\BATCH\utils\

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Ok I'm an idiot! I thank you so much for your help! I was testing on one pc and trying to make it work on another. I was maping to Z:\Patches then trying to copy Z:\Patches\Map TECONSOLE Drive.exe DUH! I should have been using just Z:\Map TECONSOLE Drive.exe.

Thank you so much. I'm going to beer now!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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