Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Batch move to directory that may not exist

Tags:

In a Windows batch file I am trying to move a file to a directory which may not currently exist. Because the directory is not there, when I do the move I see an error like:

The system cannot find the path specified

move c:\aaa\bbb\ccc\ddd\myfile.txt c:\aaa\111\222\333\444\mytext.txt 

How can I easily create the path that I want to move to if it doesn't currently exist? For example here, directory 111 may not exist yet under aaa. I want the whole path structure to be created and then the file moved.
I had thought that it would just create the whole path for me as part of the move.

like image 762
George Hernando Avatar asked Aug 31 '11 23:08

George Hernando


1 Answers

Try:

md c:\aaa\111\222\333\444 2> nul 

before your Move command.

md makes directories recursive, so if there are no parent directories to 444, it will keep creating hierarchically. The "2> nul" ensures that if you have the directory already, your command wouldnt error out.

like image 86
Arun Avatar answered Oct 04 '22 07:10

Arun