Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to move all folders in a directory called Profile.V2 out of the directory and then I want to delete the directory. I'm using a bat file to do this which is below, this works perfectly except when a folder with the same name already exists in the location I am moving the files/folders to, this causes the bat file to stop and a prompt to appear asking if it is Ok to overwrite the folder. The move command has an argument /Y that surpress the prompt, however if I place it after "move" in my bat file it doesn't work. Can anyone spot why and where should it go?

cd Profile.V2
for /f "delims=" %%a in ('dir /b') do (
  move "%%a" H:\
RD /S /Q H:\Profile.V2

Many thanks Steve

share|improve this question
try: echo y|move "%%a" h:\ – jftuga Sep 2 '11 at 15:31

Well. I would just do "move /Y . H:\" As far as I can tell that does the same as the for loop.

The /Y goes immediately after move and has to be upper-case.

(Officially it isn't case sensitive, but I know from experience that somehow it does matter on some systems. I've never managed to find out why.)

share|improve this answer

The Move command requires that the target directory does not exist and will fail if it does. There are no command line arguments that can fix this.

You might consider this script instead:

xcopy h:\Profile.V2 h:\ /s/e/v/y
RD /S /Q H:\Profile.V2

Xcopy will copy the contents of directory Profile.V2 to the root of the H: drive, and to overwrite existing files without prompting. It will create all directories found in profile.v2, including empty ones.

Moving the contents might be a lesser goal, since your RD command removes the directory without verification.

For an explanation of the command line arguments, type:

xcopy /?
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.