Batch file move command "The system cannot find the path specified." despite correctly identifying the file to be moved

StackOverflow https://stackoverflow.com/questions/18785999

  •  28-06-2022
  •  | 
  •  

Question

I'm trying to create a batch file that creates a folder structure with a datestamp and two folders within, then moves some files into these sub-folders as a form of archiving.

After some research, i've managed to get the folder structure generating properly, however i'm still struggling to get the files moved properly.

Raw
>Archive (Batch file located in here)
>>Folder named by date
>>>IN
>>>OUT
>IN
>OUT

The Batch file code i have is below:

for /f "skip=1" %%d in ('wmic os get localdatetime') do if not defined mydate set mydate=%%d
md %mydate:~0,8%\IN
md %mydate:~0,8%\OUT
move /y "C:\Main Database\Raw\IN\*.CSV" "C:\Main Database\Archive\%mydate:~0,8%\IN\*.csv"
move /y "C:\Main Database\Raw\OUT\*.CSV" "C:\Main Database\Archive\%mydate:~0,8%\OUT\*.csv"
pause

As previously mentioned, the folder structure of (Date)->(IN & OUT) works fine, but when it comes to the file moving, something slips up.

here is the output from the batch file running:

C:\HYS Database\Raw\Archive>for /F "skip=1" %d in ('wmic os get localdatetime')
do if not defined mydate set mydate=%d

C:\HYS Database\Raw\Archive>if not defined mydate set mydate=20130913130421.4590
00+060

 :\HYS Database\Raw\Archive>if not defined mydate set mydate=

C:\HYS Database\Raw\Archive>md 20130913\IN

C:\HYS Database\Raw\Archive>md 20130913\OUT

C:\HYS Database\Raw\Archive>move /y "C:\HYS Database\Raw\IN\*.CSV" "C:\HYS Datab
ase\Archive\20130913\IN\*.csv"
C:\HYS Database\Raw\IN\INLIST_HYS,HN51KTG,2013-09-13,10-05-55-372.CSV
The system cannot find the path specified.
        0 file(s) moved.

C:\HYS Database\Raw\Archive>move /y "C:\HYS Database\Raw\OUT\*.CSV" "C:\HYS Data
base\Archive\20130913\OUT\*.csv"
C:\HYS Database\Raw\OUT\OUTLIST_HYS,HN51KTG,2013-09-13,10-01-24-291.CSV
The system cannot find the path specified.
        0 file(s) moved.

C:\HYS Database\Raw\Archive>pause
Press any key to continue . . 

It looks to me as though it is having trouble seeing the source file, despite correctly identifying it within the output.

I'm completely new to writing batch files, and what I have so far was cobbled together from looking through answers from various other people having similar problems, however it hasn't completely solved the problems.

If anybody has and suggestions on how i can sort this out, it would be very much appreciated.

Was it helpful?

Solution

Shouldn't your target path be:

"C:\Main Database\Raw\Archive\%mydate:~0,8% ...  ?

it is:

C:\Main Database\Archive\%mydate:~0,8% ...

=>

move /y "C:\Main Database\Raw\IN\*.CSV" "C:\Main Database\Raw\Archive\%mydate:~0,8%\IN"
move /y "C:\Main Database\Raw\OUT\*.CSV" "C:\Main Database\Raw\Archive\%mydate:~0,8%\OUT"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top