BAT to create folders from partial filename and move

April 15, 2012 at 18:13:11
Specs: Windows 7
Hi,

I''ve been playing around with a few BAT files but with no luck at all. What I'm after is a BAT file for my HTPC to create folders from tv recording filenames and move them into their appropriate folders etc.

It's probably been asked before but I couldnt find a solution on the net.

So basically I want to take these files and move them into a series folder for each show.

Scrubs_CH10_2012_05_12_18_59_00.wtv
Scrubs_CH10_2012_08_11_18_44_00.wtv
Scrubs_CH10_2012_04_08_22_16_00.wtv

(A folder called Scrubs would be created and all files matching would be moved there)

NCIS_CH7_2012_05_12_18_59_00.wtv
NCIS_CH7_2012_08_11_18_44_00.wtv
NCIS_CH7_2012_04_08_22_16_00.wtv

(A folder called NCIS would be created and all files matching would be moved there)

All of the filenames have an underscore in common right after the name of the show so basically everything before the underscore would be the variable to create the folder. I just dont know how to trim the filename etc to do this.

Havent got any code to post sorry - bit of a noob when it comes to FOR loops.

Thanks in advance


See More: BAT to create folders from partial filename and move

Report •

#1
April 15, 2012 at 18:24:33
I found this from another thread that seems to do the trick...

@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/a-d *.wtv') do (
for /f "tokens=1 delims=_" %%f in ("%%~Na") do (
if not exist %%f md %%f
move %%a %%f
)
)


Will test and let you know....


Report •
Related Solutions


Ask Question