Jump to content

FILE COPY (all caps cause I'm dumb)


 Share

Recommended Posts

HI,

I'm new to autoit. I've created two simple scripts to copy documents from a file server and vice versa. I would like to create a error handler to display a message box telling me if the files were successfully copied or if it failed. Any help would be appreciated. thanks.

Steveb

Link to comment
Share on other sites

Wrong place, should be in support.

EDIT: moved to support by Larry

Edited by Larry


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

thanks for the quick response. I added the code but I get a file copy failed even though the file

did appear to copy. This is my code:

FILECOPY("C:\MYDOCS\*.*", "C:\test\MyDocs\", 1)

If FileCopy('source', 'destination') Then

MsgBox(0x40000, '', 'File copied')

Else

MsgBox(0x40000, '', 'File copy failed')

EndIf

Check if the condition is true with the copy.

If FileCopy('source', 'destination') Then
    MsgBox(0x40000, '', 'File copied')
Else
    MsgBox(0x40000, '', 'File copy failed')
EndIf

:whistle:

Link to comment
Share on other sites

The reason that it says it failed is because you are trying to copy twice. Loose the first line of your script and it will work.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

How would I go about doing that?

Would there be a way to add a status indicator?

Since you are using a wildcard for the source, then you may want to have a look at using FileFindFirstFile() & FileFindNextFile() for checking each file copied for precise error results.

Link to comment
Share on other sites

Example

$path = 'C:\MYDOCS' 
$handle_search = FileFindFirstFile($path & '\*.*')
If $handle_search <> -1 Then
    While 1
        $file_found = FileFindNextFile($handle_search)
        If @error Then ExitLoop
        If StringInStr(FileGetAttrib($file_found), 'D') Then
            ContinueLoop
        EndIf
        If Not FileCopy($path & '\' & $file_found, 'C:\test\MyDocs\') Then
            MsgBox(0x40000, '', 'File copy error with ' & $path & '\' & $file_found)
        EndIf
    WEnd
    FileClose($handle_search)
Else
    MsgBox(0x40000, '', 'Failed to open search handle')
EndIf
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...