'Backup batch eating first part of some names
I have made a backup batch file which scans a folder for files and moves them over 0byte copies in a premade 0byte directory clone. It works fine for the most part of finding and moving 2000+ files and rebuilding a tree from them but I have found a few names are having their first half eaten and this causes multiple files to be moved over to a singular 0byte file.
@ECHO OFF
@SETLOCAL enableextensions disabledelayedexpansion
set "SDPath=MiSTer_SD"
set "backupPath=_ROOT"
for /R "%SDPath%" %%G in (*.*) do (
if %%~zG EQU 0 (
for /R %backupPath% %%g in ("*%%~nxG") do (
MOVE "%%g" "%%G" )
)
)
The output looks like this when things are going wrong
D:\_WORK\TOOLS\MiSTer_REBUILD>(if 0 EQU 0 (for /R "_ROOT" %g in ("*Beyblade (USA).chd") do (MOVE "%g" "D:\_WORK\TOOLS\MiSTer_REBUILD\MiSTer_SD\Beyblade\Beyblade (USA).chd" ) ) )
D:\_WORK\TOOLS\MiSTer_REBUILD>(MOVE "D:\_WORK\TOOLS\MiSTer_REBUILD\_ROOT\Beyblade (USA).chd" "D:\_WORK\TOOLS\MiSTer_REBUILD\MiSTer_SD\Beyblade\Beyblade (USA).chd" )
1 file(s) moved.
D:\_WORK\TOOLS\MiSTer_REBUILD>(if 0 EQU 0 (for /R "_ROOT" %g in ("*Blade (USA).chd") do (MOVE "%g" "D:\_WORK\TOOLS\MiSTer_REBUILD\MiSTer_SD\Blade\Blade (USA).chd" ) ) )
D:\_WORK\TOOLS\MiSTer_REBUILD>(MOVE "D:\_WORK\TOOLS\MiSTer_REBUILD\_ROOT\Blade (USA).chd" "D:\_WORK\TOOLS\MiSTer_REBUILD\MiSTer_SD\Blade\Blade (USA).chd" )
1 file(s) moved.
D:\_WORK\TOOLS\MiSTer_REBUILD>(MOVE "D:\_WORK\TOOLS\MiSTer_REBUILD\_ROOT\Bushido Blade (USA).chd" "D:\_WORK\TOOLS\MiSTer_REBUILD\MiSTer_SD\Blade\Blade (USA).chd" )
1 file(s) moved.
D:\_WORK\TOOLS\MiSTer_REBUILD>(if 0 EQU 0 (for /R "_ROOT" %g in ("*Boxing (USA).chd") do (MOVE "%g" "D:\_WORK\TOOLS\MiSTer_REBUILD\MiSTer_SD\Boxing\Boxing (USA).chd" ) ) )
D:\_WORK\TOOLS\MiSTer_REBUILD>(MOVE "D:\_WORK\TOOLS\MiSTer_REBUILD\_ROOT\Boxing (USA).chd" "D:\_WORK\TOOLS\MiSTer_REBUILD\MiSTer_SD\Boxing\Boxing (USA).chd" )
1 file(s) moved.
D:\_WORK\TOOLS\MiSTer_REBUILD>(MOVE "D:\_WORK\TOOLS\MiSTer_REBUILD\_ROOT\HBO Boxing (USA).chd" "D:\_WORK\TOOLS\MiSTer_REBUILD\MiSTer_SD\Boxing\Boxing (USA).chd" )
1 file(s) moved.
I know its to do with how i have written ("*%%~nxG") but im unsure of how to fix it
I cant for the life of me figure out why its grouping a few like name source files together and overwriting a single destination file with them? Any help is greatly appreciated, or even a different approach to the whole backup idea.
Solution 1:[1]
for /R %backupPath% %%g in ("*%%~nxG") do (
Says : For all files that end with %%~nxG
Blade (USA).chd and Bushido Blade (USA).chd both match this criterion, so both will be moved.
Perhaps if you were to remove the * it would accomplish what you want.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Magoo |
