Sign in to follow this  
Followers 0
Vacuus

DirCopy - can't copy from root of a drive?

6 posts in this topic

Heya all. I'm a C++ programmer by trade, and needed a way to backup my USB drive. After mucking around with Boost::Filesystem for a while, I quite accidentally stumbled upon AutoIt. I was impressed at how easy it was to use - in an hour, I've written a script that (should) back up my Flash Drive completely, and then update it appropriately.

However, I'm having some issues. I've been able to backup the drive, and keep settings in an ini file, but I can't seem to "Update" the USB correctly. I'm using DirCopy, and would like to go from E:\ to H:\, however this never seems to happen. The strangest thing is, that when I change E:\ to a subdirectory, it'll work great (i.e E:\C++), however I already know I can copy from a root directory, as I've been doing so with the previous copy call (From H:\ to My Documents)...

Here's the copy command (and error checking) I'm using, if it helps:

If StringInStr($CopyDir, "\", 0, -1) == 0 Then
    $ret &= "\"
EndIf   
$ret = DirCopy($CopyDir, $usb&":\", 1)
If $ret == 0 Then
    MsgBox(48, "Error!", "Couldn't copy from "&$CopyDir&" To "&$usb&":\")
    Exit
EndIf

I'll attach the entire script as well.

Cheers.

flashback.au3

Share this post


Link to post
Share on other sites

I'm not sure I get your use of $ret here, adding "\" to it instead of $CopyDir. Since you only do one immediate compare on the return value, it doesn't need to be saved in a variable anyway.

How about this instead:

If Not StringInStr($CopyDir, "\") Then $CopyDir &= "\"
If DirCopy($CopyDir, $usb & ":\", 1) Then
    MsgBox(64, "Debug: Success", "Successfull copy from " & $CopyDir & " To " & $usb & ":\")
Else
    MsgBox(16, "Debug: Error", "Couldn't copy from " & $CopyDir & " To " & $usb & ":\")
    Exit
EndIf

:shocked:


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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

According to the help file, CopyDir does NOT want the trailing backslash.

So I would think the following would be what you want.

If StringRight(StringStripWS($CopyDir,2),1) = "\" Then $CopyDir =StringTrimRight($CopyDir,1)
If DirCopy($CopyDir, $usb & ":", 1) Then
    MsgBox(64, "Debug: Success", "Successfull copy from " & $CopyDir & " To " & $usb & ":")
Else
    MsgBox(16, "Debug: Error", "Couldn't copy from " & $CopyDir & " To " & $usb & ":")
    Exit
EndIf

Edit: spelling.

Edited by eltorro

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

PSaltyDS: $ret is a habit from a bunch of other languages... I know, I shouldn't ;)

Correct me if I'm wrong, but, I think, using StringInStr($CopyDir, "\") instead of StringInStr($CopyDir, "\", -1), could possibly add a trailing backslash when it's not needed (I think - more than a little tired here), doesn't matter anyway :(

Strangely, Eltorro, your suggestion just seemed to copy files from the working directory of the script :S. I'm all out of time at the moment, but I'll have a bit of a play around and get back to you with what happens.

Cheers, and thanks for all of your help :shocked:

Edit: Wait, how does AutoIt Handle file copying anyway? The script itself is inside the CopyDir... I remember DOS had a similar thing, where you could copy only from your working directory on each partition.. Doubt this is related, as AutoIt seems to use Windows API calls, however you never know... (I suppose, you did answer my question though :P)

Edited by Vacuus

Share this post


Link to post
Share on other sites

@Vacuus

I have nothing for you about DirCopy problem

but I looked at you USB backup script (it's nice)

and find that you can use DriveGetDrive() function instead of your $alph[] array.

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