On an industrial PC there is a recovery partition running Windows PE. On this WPE environment there are some batch scripts running that offer the user some choices. E.g. "Press 1 for this, press 2 for that", etc.
I'm currently working on an operation that includes moving and deleting files to an external drive. Using the following commands I can move and delete files:
::Create a new folder on the external drive
if not exist "F:\Backup\TemporaryFiles\" mkdir F:\Backup\TemporaryFiles
::Move log files
move /y "%dataVolume%\system\LogFile\*.log" "F:\Backup\TemporaryFiles\"
move /y "%dataVolume%\system\LogFile\*.gz" "F:\Backup\TemporaryFiles\"
::Delete PNG files
del "%dataVolume%\system\LogImg\*.png" /f/q
:: Reboot safely
wpeutil reboot
However, after rebooting both the source directories from which the files were moved as well as the target directory on the external drive are corrupted. Using chkdsk
they can be restored, but of course it is not a stable state.
According to this question on Super User, wpeutil reboot
can be used to safely reboot the PC and flush all data to disk. I would expect that this is enough to avoid corrupt directories, but it seems that indexing is broken after the move and/or delete operations, because chkdsk /f
tells me that corrupt indices were restored.
Are the move commands not running synchronously?
I.e. is batch not waiting until move has finished before it executes the next command?
How can I ensure that my indices don't get destroyed when moving and deleting files?
Since move
is working synchronously and wpeutil reboot
should flush all buffers to disk, I should have been fine with what I'm doing. However, I decided to make sure that all buffers are actually flushed to disk (i.e. the USB drive), by using sync and waiting for it to return:
move /y "\TmpLogFile\*.gz" "%%d\Backup\TemporaryFiles\"
START /WAIT cmd /c "sync.exe" "-r -e %%d"
wpeutil reboot
%%d
is holding the letter assigned to the USB drive.