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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With