Alex Rivera | Logout

Windows Batch move to directory that may not exist

Asked 2011-08-31T23:45:00.803
29

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.

Edit
Report

1 Answer

10
if not exist c:\aaa\111\222\333\444 md c:\aaa\111\222\333\444
Move c:\aaa\bbb\ccc\ddd\myfile.txt c:\aaa\111\222\333\444\mytext.txt
answered 2011-09-01T09:21:27.227

Your Answer