Sunday, 25 August 2013

Batch file Loop with spaces

Batch file Loop with spaces

I have this tiny annoying thing that is driving me nuts. I need to loop
through a directory and move files contained within a subdir to another
location.
This works fine for folders that don't contain any spaces, but I have some
directories that contain spaces, which do not work. I've tried adding some
"" around the file location, but that doesn't work either.
This is what I have:
for /f "usebackq" %%m in (`dir /b D:\adir\dir with spaces`) do (
MOVE /Y "D:\adir\dir with spaces\%%m\*.*" "D:\bdir\dir with spaces"
RD /q D:\adir\dir with spaces\%%m
)

No comments:

Post a Comment