1

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

Steve Lee
  • 11
  • 1
  • 1
  • 2

2 Answers2

1

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

Tonny
  • 6,332
  • 1
  • 18
  • 31
0

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 /?
RobW
  • 2,806
  • 1
  • 19
  • 22