I'm in need of a batch command that will look into a directory's sub folders and find a partial file name. If that file exists, then move that directory otherwise leave it alone.
I have a folder full of movies:
D:\Movies\movie1\
\movie2\
\movie3\
Within each movie folder I would like to know if it has a trailer downloaded into the folder, if so then move that directory to x:\movies
. I say partial file name as every trailer file will include the title of the movie with "-trailer
" added to the end (f.e. The Interview (2014)-trailer
).
Let's look for a solution from Windows CLI (Command Line Interpreter) with
->
prompt using An A-Z Index of the Windows CMD command line and with next scenario:To find all those files under
MOVIES
subfolder with-trailer
added to the filename end preceding.
of file extension:To get folder names only:
But here the
movie2
appears more than once! And, moreover, themove
command does not allow source directory with trailing backslash:Therefore we need switch from Windows shell (CLI) to batch scripting. Create file
28167824.bat
(e.g withnotepad
and save it toD:\bat\StackOverflow
folder):Run this batch script, the template of next
move
commands is the same as in that successfulmove
command mentioned above:Bingo! Now we could remove
rem
beforemove "%srcfolder%" "d:\test\xMovies\"
, save the script and run it:And here is final configuration, cf. starting scenario: