Jump to content

Recommended Posts

Posted

Assume I want to move files from local drive to

  1. an external detachable drive
  2. should that drive is detached/not available, move it to another local drive

What is the best practice?

Assume $Repository is the Folder in the detachable drive
Assume $LocalDrive is the Folder to another local drive

Should I:

if FileExists($Repository) then
   Filemove(...., $Repository....)
else
   FileMove( ...., $LocalDrive...)
endif

or

If NOT FileMove( ...., $Repository..) then
    FileMove(...$LocalDrive....)
endif?

 

I know both will work, but what is the best practice?

I assume doing the FileExists one is better. What do you think?

 

Thanks!  

 

 

 

Posted

Since you're talking about moving files to different drives, you should know that it's not really going to move them, but instead it copies.

So as a general rule, and if you want to do it proper, i'd say you do a FileExists on the drive for the destination,

then a FileGetSize on the original file, then do a copy, and then another FileGetSize on the destination file.

 

 

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted
  On 5/19/2020 at 12:03 PM, careca said:

it's not really going to move them, but instead it copies

Expand  

What? Please explain what you mean by this. I just tried this and it moves the files across drives for me

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

  Reveal hidden contents
Posted

Has to copy, the file doesn't exist in the other drive.

As stated in the remarks for filemove:

"If the source and destination paths are on different volumes a copy and delete operation is performed rather than a move."

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

To @careca's point, technically the file move operation between volumes is a copy from source, then a deletion from source after the copy.  Not sure how important that detail is as far as accomplishing the goal of moving a file, but I suppose it's useful to know how it works.

Also, due to the nature of how it works, I would expect that there is some sort of successful copy validation already inherent in the process before it deletes the original, otherwise if the move didn't actually copy the file accurately and deleted the original you'd be at risk of losing integrity of the file data and be screwed.

If you are really worried about it, perhaps perform the copy yourself, compare the two files, then delete the original. If I was worried checking a transferred file I might employ something to verify integrity more precisely than file sizes (i.e. a hash/checksum comparison).

Posted (edited)

I agree, a checksum is a better idea.

Found a post with it

#include <Crypt.au3>
;Get SHA1
Local $File = FileOpenDialog("Select a file", EnvGet("systemdrive"), "All (*.*)")
_Crypt_Startup()
$sha1 = _Crypt_HashFile($File, $CALG_SHA1)
MsgBox(64 + 262144, '$sha1', $sha1)
_Crypt_Shutdown()

 

Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

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
  • Recently Browsing   0 members

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