windows - how to move folders with a loop over folders (in batch)? -


situation:

i try move files inside loop in shell code not working.

for /d %%f in (*) (    if "%%f" neq "%directorytoputfilesin%" (      move /y "%%f" "%directorytoputfilesin%"   ) ) 

after hours of testing it, realized it's because %%f pointing folder, hence file cannot moved.

bad solution:

the way made work , confirmed suspicions saving value of %%f in variable , using variable on next turn move file. note, following needs initialisation of %precedentfile% first turn.

for /d %%f in (*) ( move /y "%precedentfile%" "%directorytoputfilesin%"    if "%%f" neq "%directorytoputfilesin%" (      move /y "%%f" "%directorytoputfilesin%"      set precedentfile=%%f   ) 

problem:

this solution not practical , feels wrongs. there way adapt current code it, or way?

try below code move files 1 folder in batch script:

for /f %%a in ('dir /a:-d /b') move /y "%%~fa" "%directorytoputfilesin%" 

explanation :

dir /a:-d /b : command list files in directory  move /y "%%~fa" "%directorytoputfilesin%" : move files in directory command executed destination have mentioned. %%~fa : command full qualified path of file it's name. 

try below code move directories : below command move directories in path command executed destination provided. in h:\ drive, change accordingly

for /d %%b in (*) move /y "%%~fb" "h:\" 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -