Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Batch File: Look for directory, if not exist, create, then move file to it

Tags:

batch-file

I am trying to create a batch file, or other script, to take the contents of one folder to a folder containing its name in another directory. For example:

ShowName.Episode.Title.mkv should be moved to \movies\showname. if \movies\showname\ doesn't exist, the script would create it.

There are, on average, 10-15 files at a time that would need moved.

Any ideas?

Thanks

like image 568
user2274612 Avatar asked Jul 27 '13 15:07

user2274612


1 Answers

You can conditionally create the folder with:

if not exist \movies\showname mkdir \movies\showname

To move a file into it:

move ShowName.Episode.Title.mkv \movies\showname

To get more information about these commands, open a command prompt and type:

help if

and

help move
like image 159
Ferruccio Avatar answered Oct 14 '22 10:10

Ferruccio