So just as a way to kick start some idea's i will go through how I form a tool.
As you see from my previous post I identify the need, and the goal.
now we need to flesh out individual pieces, when I script I like to accomplish it in chunks.
This allows me to repurpose those chunks in later projects speeding up the overall process.
We would assume you already have a folder you ripp to. i.e C:\temp\movies
so once that is identified we would need to know whats in there.
I would use the "Dir" command.
but we are only interested in folders not files.
so I would use something like.
"dir /AD c:\temp\movies"
Of Course we would need to collect this in a usable form like a list so I would direct the output into a text file for later use with a line like this.
"dir /AD c:\temp\movies > C:\temp\mov-mover.txt"
This will create a fresh list each time it's ran called "mov-mover.txt" and will only have folder names in it.
Next we will need to look at each line and try to determine what letter or number they start with.
Ok after thinking about it a little bit I think we will try to do this as simply as possible, to help you new scriptors grasp the idea's better.
So rather than making a fancy file sorting line we will use the dir command to make seperate files for each letter and a common one for Numbers as not too many movies start with numbers.
To keep things orginized we will make a temporary holding folder in our temp folder.
So we will need to check if it exist and make it if it doesn't.
we will do that like this.
Code:
If not exist c:\temp\nul mkdir c:\temp
if not exist c:\temp\movtemp\nul mkdir c:\temp\movtemp
so now we should have a folder called c:\temp\movtemp
into that we will want to do scans of our ripp staging area for movie folders based on their names.
like this.
What we will want to do is clean the folder first to make sure previously ran data is gone.
Then run scans for each needed number/letter.
Code:
Del /Q/S c:\temp\movtemp\*.txt
Dir /AD C:\temp\movies\A* > C:\temp\movtemp\mov-a.txt
Dir /AD C:\temp\movies\B* > C:\temp\movtemp\mov-b.txt
Dir /AD C:\temp\movies\C* > C:\temp\movtemp\mov-c.txt
Dir /AD C:\temp\movies\D* > C:\temp\movtemp\mov-d.txt
Dir /AD C:\temp\movies\E* > C:\temp\movtemp\mov-e.txt
Dir /AD C:\temp\movies\F* > C:\temp\movtemp\mov-f.txt
Dir /AD C:\temp\movies\G* > C:\temp\movtemp\mov-g.txt
Dir /AD C:\temp\movies\H* > C:\temp\movtemp\mov-h.txt
Dir /AD C:\temp\movies\I* > C:\temp\movtemp\mov-i.txt
Dir /AD C:\temp\movies\J* > C:\temp\movtemp\mov-j.txt
Dir /AD C:\temp\movies\K* > C:\temp\movtemp\mov-k.txt
Dir /AD C:\temp\movies\L* > C:\temp\movtemp\mov-L.txt
Dir /AD C:\temp\movies\M* > C:\temp\movtemp\mov-m.txt
Dir /AD C:\temp\movies\N* > C:\temp\movtemp\mov-n.txt
Dir /AD C:\temp\movies\O* > C:\temp\movtemp\mov-o.txt
Dir /AD C:\temp\movies\P* > C:\temp\movtemp\mov-p.txt
Dir /AD C:\temp\movies\Q* > C:\temp\movtemp\mov-q.txt
Dir /AD C:\temp\movies\R* > C:\temp\movtemp\mov-r.txt
Dir /AD C:\temp\movies\S* > C:\temp\movtemp\mov-s.txt
Dir /AD C:\temp\movies\T* > C:\temp\movtemp\mov-t.txt
Dir /AD C:\temp\movies\U* > C:\temp\movtemp\mov-u.txt
Dir /AD C:\temp\movies\V* > C:\temp\movtemp\mov-V.txt
Dir /AD C:\temp\movies\W* > C:\temp\movtemp\mov-w.txt
Dir /AD C:\temp\movies\X* > C:\temp\movtemp\mov-x.txt
Dir /AD C:\temp\movies\Y* > C:\temp\movtemp\mov-y.txt
Dir /AD C:\temp\movies\Z* > C:\temp\movtemp\mov-z.txt
Dir /AD C:\temp\movies\0* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\1* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\2* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\3* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\4* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\5* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\6* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\7* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\8* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\9* >> C:\temp\movtemp\mov-#.txt
You might notice for numbered names I used a ">>" instead of a single this is for appending to the end of a text file rather than replacings.
it allows me to have multiple commands dump their output into one file.
So now that we have several files with lists of names sorted by alpha and number we need to run a command against each name within each list we will do this with a "For" command.
Ok, so we can gather folder list, as an example the output looks like this.
Attachment:
mov-u.jpg [ 62.76 KiB | Viewed 15428 times ]
As you can see it's not just a simple list so we will need to be able to deal with the unnecesarry data.
Lucky for us the trusty "FOR" command has just what we need.
you will notice the first five lines are junk so we can skip them.
so our test line looks like this.
"FOR /I "Skip=5 tokens=4" %%A IN (c:\temp\movtemp\mov-a.txt) DO ( command goes here )"
This will skip the first five lines, and then take the fourth word in from the left and treat it as a folder name.
you might notice it will attempt to run against the last two lines, which will result in no action as in either case by the time we reach the end of the file no titles of that name will exist it will simply fail the next step.
With an error file not found.
When dealing with paths it's best if they are defined, and many scripts will have a beginning section dedicated to defining paths and constants.
So any thing that won't change or at least not very often you want to predefine.
Such as in the case of orginized movie folders.
On my system for the first Drive if you will, any movies the start with numbers or A-F go here into seperate folders.
So we will set predefined definitions for those paths.
Note: any line that begins with "REM" means it's ignored and used for remarks, this is very useful for making notes within your tools.
At this point we have enough bits and pieces to start putting our script into order of course it will evolve as we test each piece along the way.
We will call this one MovieMover.cmd
Code:
Begin Script
rem ******path definitions**********************
set path-#=F:\#
set path-A=F:\A
set path-B=F:\B
set path-C=F:\C
set path-D=F:\D
set path-E=F:\E
set path-F=F:\F
rem *****Check for folders**********************
If not exist c:\temp\nul mkdir c:\temp
if not exist c:\temp\movtemp\nul mkdir c:\temp\movtemp
Rem ********Begin list making*******************
Del /Q/S c:\temp\movtemp\*.txt
Dir /AD C:\temp\movies\A* > C:\temp\movtemp\mov-a.txt
Dir /AD C:\temp\movies\B* > C:\temp\movtemp\mov-b.txt
Dir /AD C:\temp\movies\C* > C:\temp\movtemp\mov-c.txt
Dir /AD C:\temp\movies\D* > C:\temp\movtemp\mov-d.txt
Dir /AD C:\temp\movies\E* > C:\temp\movtemp\mov-e.txt
Dir /AD C:\temp\movies\F* > C:\temp\movtemp\mov-f.txt
Dir /AD C:\temp\movies\G* > C:\temp\movtemp\mov-g.txt
Dir /AD C:\temp\movies\H* > C:\temp\movtemp\mov-h.txt
Dir /AD C:\temp\movies\I* > C:\temp\movtemp\mov-i.txt
Dir /AD C:\temp\movies\J* > C:\temp\movtemp\mov-j.txt
Dir /AD C:\temp\movies\K* > C:\temp\movtemp\mov-k.txt
Dir /AD C:\temp\movies\L* > C:\temp\movtemp\mov-L.txt
Dir /AD C:\temp\movies\M* > C:\temp\movtemp\mov-m.txt
Dir /AD C:\temp\movies\N* > C:\temp\movtemp\mov-n.txt
Dir /AD C:\temp\movies\O* > C:\temp\movtemp\mov-o.txt
Dir /AD C:\temp\movies\P* > C:\temp\movtemp\mov-p.txt
Dir /AD C:\temp\movies\Q* > C:\temp\movtemp\mov-q.txt
Dir /AD C:\temp\movies\R* > C:\temp\movtemp\mov-r.txt
Dir /AD C:\temp\movies\S* > C:\temp\movtemp\mov-s.txt
Dir /AD C:\temp\movies\T* > C:\temp\movtemp\mov-t.txt
Dir /AD C:\temp\movies\U* > C:\temp\movtemp\mov-u.txt
Dir /AD C:\temp\movies\V* > C:\temp\movtemp\mov-V.txt
Dir /AD C:\temp\movies\W* > C:\temp\movtemp\mov-w.txt
Dir /AD C:\temp\movies\X* > C:\temp\movtemp\mov-x.txt
Dir /AD C:\temp\movies\Y* > C:\temp\movtemp\mov-y.txt
Dir /AD C:\temp\movies\Z* > C:\temp\movtemp\mov-z.txt
Dir /AD C:\temp\movies\0* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\1* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\2* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\3* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\4* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\5* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\6* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\7* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\8* >> C:\temp\movtemp\mov-#.txt
Dir /AD C:\temp\movies\9* >> C:\temp\movtemp\mov-#.txt
Rem***end list making**************************
rem ******begin move section*******************
FOR /I "Skip=5 tokens=4" %%A IN (c:\temp\movtemp\mov-a.txt) DO (
move c:\temp\movies\%%A %path-A%
)
FOR /I "Skip=5 tokens=4" %%A IN (c:\temp\movtemp\mov-b.txt) DO (
move c:\temp\movies\%%A %path-B%
)
FOR /I "Skip=5 tokens=4" %%A IN (c:\temp\movtemp\mov-c.txt) DO (
move c:\temp\movies\%%A %path-C%
)
Of course this is now a work in progress and garanteed to fail and break.
Keep watching this post for updates as I will continue to flesh this out over the next couple of days.