Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

@ECHO OFF
H:
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
1  
try: echo y|move "%%a" h:\ –  jftuga Sep 2 '11 at 15:31

2 Answers 2

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:

@ECHO OFF
H:
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

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

Your Answer

 
discard

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.