Batch moving files to another folder/directory in Windows?

I am getting an error message to the effect of unable to move files to a single file. I am not trying to do this. What I am trying to do is move files from one folder to another folder (staging) and then deleting the original folder.

If you can show me a better way to do this since I am not doing this correctly.

Here is my .cmd file:

Y:
move "Y:\ABC_files\*.js" "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files\"
move "Y:\ABC_files\*.CSS" "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files\"
move "Y:\ABC_files\*.png" "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files\"
move "Y:\ABC_files\*.htm" "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files\"
move "Y:\ABC_files\*.gif" "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files\"
move "Y:\ABC.htm "C:\Documents and Settings\user\Desktop\ABC_Stage\"
rmdir "Y:\ABC_files"
C:\"Program Files"\"App X"\App-IDE.exe -r ABC4.run
4

4 Answers

Personally, I would prefer XCOPY here since it has more options that may be useful, especially if you change the batch file, and then remove the old directory and files using a switch.

I would also dump the quotes unless there is an actual space in the file location or name. In your last move, you actually dropped a quote, and that would probably produce an error. Your last statement is also incorrect: You only put the quotes around the WHOLE command before switches, not portions of it. I added the switches I consider potentially useful: You can see what each does by doing an xcopy /? at a command prompt. I would also question whether your, in your last copy, if abc.htm is really in the root directory...check that, and edit accordingly, if necessary. Lastly, make sure you edit the user portion to reflect your username. I don't know anything more about your last line since that is application-specific.

Y:
xcopy Y:\ABC_files\*.js "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files\"
xcopy Y:\ABC_files\*.css "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files\"
xcopy Y:\ABC_files\*.png "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files\"
xcopy Y:\ABC_files\*.htm "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files\"
xcopy Y:\ABC_files\*.gif "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files\"
xcopy Y:\ABC.htm "C:\Documents and Settings\user\Desktop\ABC_Stage\"
rd Y:\ABC_files /s /q
del Y:\ABC.htm
"C:\Program Files\App X\App-IDE.exe" -r ABC4.run
0

There are two solutions that suggest themselves to what you want to do. If you want to copy only the .js, .css, .htm, etc. files, go with the first solution. If you really want everything in the source folders, go for the second. Note that both give you the opportunity to make sure everything's ok before deleting the source files. Also, it assumes that the target directory already exists.

Solution 1:

for %%f in (js css png htm gif) do (
copy Y:\ABC_files\*.%%f "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files"
)
copy Y:\ABC.htm "C:\Documents and Settings\user\Desktop\ABC_Stage"
echo Check that your files copied correctly, then
pause
rmdir /s /q Y:\ABC_files
"C:\Program Files\App X\App-IDE.exe" -r ABC4.run

Solution 2:

xcopy Y:\ABC_files\*.* "C:\Documents and Settings\user\Desktop\ABC_Stage\ABC_files" /s /e
echo Check that your files copied correctly, then
pause
rmdir /s /q Y:\ABC_files
"C:\Program Files\App X\App-IDE.exe" -r ABC4.run
2

Try the following command

move "C:\Documents and Settings\amitrajk\Desktop\New Folder\*.*" "C:\Documents and Settings\amitrajk\Desktop\New Folder\InFolder"

Why not move the entire directory? That way you have all your files copied with one command without having to clean anything up.

Move Y:\ABC_Files "%userprofile%\desktop\staging"

Note: %userprofile% is a variable for C:\documents and settings\CurrentlyLoggedOnUser\

In batch files, type these to achieve file relocation:

Move /-y "Y:\ABC_Files" "%userprofile%\desktop\staging"

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like