How to move a file to a USB drive that has a variable drive letter range dependant on the machine it could be drive E, F, G or H, in Windows Embedded XP, there is only ever one USB drive installed at a time, so it can move only if it is fitted, I can create the file and it moves in Windows 7 but not in Windows Embedded XP, what are the differences in the options available for this in XP, the script will only be used on XP machines.
REM ------ Creation of the ZIP file ------
%SupervisorPath%\7-ZipPortable\App\7-Zip\7z a -tzip %BackupPath%\Backup\%FileStamp%.zip %BackupPath%\Backup\
REM ------ Move the backup file to a USB drive with File Name and Date Stamp ------
for %%A in (E F G H) do if exist %%A: (
echo Moving files to USB drive %%A:
move /y "%BackupPath%\Backup\%FileStamp%.zip" %%A: >nul && (
echo Files moved to USB drive successfully
goto :break
)
)
:break
Can I also create an error message if the file is not moved and then delete the file, as it takes up valuable space on the drive?
Here is a solution I use. There is a requirement that the USB drive has been named and you know it. So lets say your USB is named "8GB"
If you run the following command:
You get a list of your drives including the VolumeName.
Using this list you can pipe it to the Find command like so:
Which will return all information about your drive with the VolumeName 8GB. It will look something like this.
Now with this command we can take it further and redirect its output to a file. Like so.
After the information we want has been stored we can read it back into a variable using:
Now that variable has the whole string but we only want the drive letter so we shorten it like so:
Now the variable driveLetter contains just your drive letter "F:"
So if you want it all together:
As for checking if the move command fails. If any command fails move included they set the variable errorlevel to some value other than 0 (0 is for successful execution) Therefore all you need to do is add an if statement after the move command like: