Solved Batch MOVE command doesn't move all files

October 30, 2013 at 11:45:12
Specs: Windows 7
I am working on a batch file move for old files. I made some test folders and copied some old files. Long story short, there are 4 that it needs to move. 3 move fine, 1 says "The syntax of the command is incorrect."

Here is the code:

rem Get the datetime in a format that can go in a filename.
set _my_datetime=%date%_%time%
set _my_datetime=%_my_datetime: =_%
set _my_datetime=%_my_datetime::=_%
set _my_datetime=%_my_datetime:/=-%
set _my_datetime=%_my_datetime:.=_%


rem Create a log of moved files.
forfiles -p "C:\test\New Files" -m *.* /D -1 /C "cmd /c ECHO @path >> "C:\test\filemove_%_my_datetime%.txt"
pause
rem Move the files.
forfiles -p "C:\test\New Files" -m *.* /D -1 /C "cmd /c MOVE @path """C:\test\New Files\Old Files\@file"
pause

Here are the files, as listed by the log it creates:

"C:\test\New Files\SolarWinds IP Address Tracker.msi"
"C:\test\New Files\Station_IDs_10_7_2013.xls"
"C:\test\New Files\Tue_10_29_2013_174807_68.txt"
"C:\test\New Files\Tue_10_29_2013_174820_52.txt"


The IP Tracker doesn't move. Any thoughts as to why? Thanks in advance.


See More: Batch MOVE command doesnt move all files

Report •

✔ Best Answer
October 31, 2013 at 09:05:24
Untested:
forfiles -p "C:\test\New Files" -m *.* /D -1 /C "cmd /c MOVE @path \"C:\test\New Files\Old Files\""

How To Ask Questions The Smart Way



#1
October 30, 2013 at 13:15:14
Well, based upon the name the difference is the spaces.

try adding this and see if it works

set _my_datetime=%_my_datetime: =%

::mike

message edited by mikelinus


Report •

#2
October 31, 2013 at 08:31:36
Mike, thanks for your reply. That variable is only used for creating a filename for the log. I don't think that has anything to do with the MOVE command itself, since the log file is made in a different "forfiles" command line.

If you think it should go somewhere in the MOVE command, can you please tell me where to add it to the code I have currently? Thanks.


Report •

#3
October 31, 2013 at 08:38:22
I just tried it again with several other files that have spaces in the names. You seem to be on the right track, as none of them would move either. If you can tell me how to fix the move command, I would be most appreciative. :-)

Report •

Related Solutions

#4
October 31, 2013 at 09:05:24
✔ Best Answer
Untested:
forfiles -p "C:\test\New Files" -m *.* /D -1 /C "cmd /c MOVE @path \"C:\test\New Files\Old Files\""

How To Ask Questions The Smart Way


Report •

#5
October 31, 2013 at 13:32:16
Razor, that was it! Thanks!!!

Report •

Ask Question