Jump to content

What is best practice for moving files?


Recommended Posts

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!  

 

 

 

Link to comment
Share on other sites

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.

 

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

3 hours ago, careca said:

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

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.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

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."

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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...