Batch move with exceptions? Or using xcopy and deleting original after? -
i have script extracts files sub-directories , deletes empty sub-directories afterwards, part extracts reads:
for /r %%a in (*.*) move "%%a" "%~dp0" is there way exception of sub-directories named "_unsorted"? know xcopy has /exclude option,
for /r %%a in (*.*) xcopy "%%a" "%~dp0" /exclude "\_unsorted\" would work, i'm not sure how delete original after it's copied have same result move
some batch-only options:
add filter loop body:
for /r %%a in (*.*) ( (echo %%~dpa | find /i "\_unsorted\" 1>nul) || move "%%a" "%~dp0" )alternatively:
for /r %%a in (*.*) ( (echo %%~dpa | find /i /v "\_unsorted\" 1>nul) && move "%%a" "%~dp0" )in both versions,
findcommand used match file's path against substring\_unsorted\. in first version,findreturnssuccessif there match ,failotherwise.movecommand called in case offail, effect of||operator`.in second version,
/vswitch reverses result offind,successmeans no match. accordingly,&&operator used callmovein case ofsuccess.apply filter file list, loop never iterates on
_unsortedentries.for /f "delims=" %%a in ( 'dir /s /b ^| find /i /v "\_unsorted\"' ) move "%%a" "%~dp0"this more essential change original script previous option, replaces
for /rloopfor /fone.basically,
for /floop used read/parse piece of text, text file or command's output. in case,dircommand provides complete list of files in current directory's tree ,findcommand filters out containing\_unsorted\in paths.for /floop reads list after it's been filtered downfind, means never hits files stored in_unsorted(sub)folders.
Comments
Post a Comment