0

I have 200 users whose files and folders all reside in a random number of nested folders and files in their user area on our server. The only guarantee is that each user has the following three folders. My Music, My Pictures, My Videos.

I would like to write a batch file that moves:

H:\My Music (and all its contents) to H:\Music

H:\My Pictures (and all its contents) to H:\Pictures

H:\My Videos (and all its contents) to H:\Video

And finally all their remaining files and folders to the following to H:\Documents

I have been fiddling with the following command and although it works and traverses the whole nested folder structure, it is limited to files and folder without spaces. I assume I need to add a token delims statement, but I can't get the syntax right.

FOR /f %%a IN ('dir "H:\My Music" /b') DO MOVE H:\My Music\%%a H:\Documents\Music

FOR /f %%a IN ('dir "H:\My Pictures" /b') DO MOVE H:\My Pictures\%%a H:\Documents\Pictures

FOR /f %%a IN ('dir "H:\My Videos" /b') DO MOVE H:\My Videos\%%a H:\Documents\Videos

FOR /f %%a IN ('dir "H:" /b') DO MOVE H:\%%a H:\Documents

How do I deal with the spaces in the file and folder names?

I know I can achieve this with XCOPY, but space is an issue. More importantly time is extremely limited. I intend to get all users to run this script, during a 30 minute training session. With most users having several GB's of files XCOPY would take more time than is available during a 30 minute session.

1
  • Why not the simple `move H:\My Music* H:\Documents\Music`, etc? Commented Dec 26, 2013 at 2:27

2 Answers 2

1

You can simplifu your code like this :

@echo off&cls
set "$Drive=h:\"
set "$folder=music Pictures Videos"

for %%a in (%$folder%) do echo MOVE "%$DRIVE%my %%a" "%$drive%Documents\%%a"
pause

I put an echo before the move that you can test if tje output is ok for you

Sign up to request clarification or add additional context in comments.

Comments

0

You need to put quotes around names that contain spaces.

Something like this should work:

FOR /f %%a IN ('dir "H:\My Music" /b') DO MOVE "H:\My Music\%%a" H:\Documents\Music

FOR /f %%a IN ('dir "H:\My Pictures" /b') DO MOVE "H:\My Pictures\%%a" H:\Documents\Pictures

FOR /f %%a IN ('dir "H:\My Videos" /b') DO MOVE "H:\My Videos\%%a" H:\Documents\Videos

FOR /f %%a IN ('dir "H:" /b') DO MOVE "H:\%%a" H:\Documents

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.