Using the move command with /Y in a bat file

batch-file

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

Best 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.)