Sign in to follow this  
Followers 0
SBROOKJR

FILE COPY (all caps cause I'm dumb)

10 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Wrong place, should be in support.

EDIT: moved to support by Larry

Edited by Larry


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

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

Share this post


Link to post
Share on other sites

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:

Share this post


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

Share this post


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



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

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

Share this post


Link to post
Share on other sites

My bad. Its working now. I really appreciate your help. thanks.

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.

Share this post


Link to post
Share on other sites

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.

Share this post


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

Share this post


Link to post
Share on other sites

search "copy with progress" in scripts and scraps, there are many to choose from

8)


NEWHeader1.png

Share this post


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

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
Sign in to follow this  
Followers 0