Jump to content

Recommended Posts

Hi everybody :)
It's the very 1st time i use the command FileCopy() and I got an issue when experimenting its parameters.

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Check_Process_Scite()

Global $aFilesToCopy[2] = ["SciTE.session", "SciTEUser.properties"]
$iFilesToCopy = UBound($aFilesToCopy)

$sDirFrom = "D:\Internet Sources 2\AutoIt - scripts pour Windows (oui)\" & _
    "AutoIt 3.3.14.5 - 16 mars 2018\Avec Installateur\"

$sDirTo = "C:\Documents and Settings\Administrateur\"

For $i = 0 To $iFilesToCopy - 1
    $iStatus = FileCopy($sDirFrom & $aFilesToCopy[$i], $sDirTo, $FC_OVERWRITE)
    If $iStatus = 0 Then
        MsgBox(BitOr($MB_TOPMOST, $MB_ICONERROR), "End of script", _
            "File " & $aFilesToCopy[$i] & _
            " could not be copied. Please check parameters")
        Exit
    EndIf
Next

MsgBox($MB_TOPMOST, "Done", _
    $iFilesToCopy & _
    " file" & (($iFilesToCopy > 1) ? ("s") : ("")) & _
    " successfully copied")

; ========================
Func Check_Process_Scite()

    Local $sProcessname = "Scite.exe"
    If ProcessExists($sProcessname) Then
        MsgBox(BitOr($MB_TOPMOST, $MB_ICONINFORMATION), $sProcessname, _
            "This process is active, please close it." & @CRLF & _
            "Then re-run the script outside Scite")
        Exit
    EndIf

EndFunc ; Check_Process_Scite()

The precedent script works without error because source path and destination path exist on my HD, so files "SciTE.session" and "SciTEUser.properties" are correctly copied from source to destination (after a check that the process Scite.exe isn't running)

Then I experimented the case where the destination path doesn't exist and the flag $FC_CREATEPATH (8) is not present, so I modified the destination path line to a non-existent path :

$sDirTo = "C:\Documents and Settings\Administrateur2\" ; added "2" in last subfolder name

I re-ran the script (without error !) and the successful message appears ("Done, 2 files successfully copied") but in fact this is how and where both files were copied :

859860184_Filecopybad.png.7ef766b1c69411461ba52c4729797122.png

"SciTE.session" was copied under a new name "Administrateur2" (1KB)
Immediately followed by "SciTEUser.properties" copied with the same new name "Administrateur2" (2KB) and overwriting the first "Administrateur2", this is not what was expected.

I have 2 remarks concerning this behavior :
1) If the non-existent destination path had been created like this :

$sDirTo = "C:\Documents and Settings2\Administrateur\" ; added "2" but not in last subfolder name

Then the error would appear when running the script, because there is a subdirectory under the non-existent folder "C:\Documents and Settings2\"

2) To solve both situations, I modified the copy line to what follows (like we did sometimes in the old Dos/Windows days where a directory name could be mixed up with a file name in some situations) :

$iStatus = FileCopy($sDirFrom & $aFilesToCopy[$i], $sDirTo & $aFilesToCopy[$i], $FC_OVERWRITE)

With this modified FileCopy line, there will be an error with both "non-existent destination path" cases, especially the annoying ".....\Administrateur2\"  one, exactly what we want :)

Of course, one could test before the copy operation that the destination path already exists but well... you got the idea.
I wrote this because the help file doesn't state that you are allowed to indicate files names in the destination path parameter.
Thanks for reading

Edited by pixelsearch

Share this post


Link to post
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

×
×
  • Create New...