::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::                                                                          :::
:::                CHFR.cmd: The Cock Hero File Renamer v0.1a                :::
:::                                                                          :::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::                                                                          :::
::: This WinNT batch script will match a folder of files against a CSV list  :::
::: containing filesizes, filenames, and other info. Matched files may be    :::
::: copied, moved, and renamed using entries from the CSV. This small batch  :::
::: file was created specifically for the easy collation and manipulation of :::
::: the Cock Hero video collection, but the variables and CSV can be easily  :::
::: manipulated to use any given set of files. I hope it proves useful.      :::
:::                                                                          :::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::                                                                          :::
::: Usage:                                                                   :::
::: CHFR.cmd /L \CSV\List.csv /F \Source\Dir /C \Copy\To /D Column#          :::
:::          /S Column# /I Column# /X SearchExt /R Template /M Template      :::
:::          /G Column# "String1[:String2[...]]" /O /U /A                    :::
:::                                                                          :::
::: /L(+) \CSV\List.csv-external CSV text file. /l+ appends. /l- for no CSV. :::
::: /F(+) \Source\Folder-to recursively search for files. /f- for no recurs. :::
::: /C(+) \Copy\To\Folder-for Matched/Renamed files. /c- Moves source files. :::
::: /O(+) set Copy/Move-to Overwrite existing files. /o- skips files instead.:::
::: /U(+) create CSV of Unmatched files (Size:Name:Ext). /u+ use MediaInfo.  :::
::: /S(+) Column#-will Sort the CSV and reload. /s- will reverse sort order. :::
::: /I(+) Column#-uses a slow but non-destructive sort. /i- reverses order.  :::
::: /D(+) Column#-will check CSV for duplicate entries. /d+ = case-sensitive.:::
::: /G(+) Column# String-will process entries containing %String% in Column#.:::
::: /M(+) MatchTemplate-for Matching source filenames to CSV column contents.:::
::: /R(+) RenameTemplate-for Renaming matched files from CSV column contents.:::
::: /X    SearchExt is a string of file eXtension(s) to search for.          :::
::: /A    Copy/Move/Rename Additional files for WDlxTV MovieSheets+ menus    :::
:::                                                                          :::
::: Overview:                                                                :::
::: /L(+) \CSV\List.csv-an external CSV text file. If used it should be the  :::
:::       first option. If omitted %SELF% is searched for CSV information.   :::
:::       If /l+ is used the contents of the external CSV is appended to the :::
:::       current database, otherwise it replaces the current database.      :::
:::       The columns of the appended file must match with the previous CSV. :::
:::       /l- will prevent loading of the internal CSV. This is useful when  :::
:::       using /u to create new CSVs as it greatly accelerates the process. :::
:::       Default: Use Internal CSV                                          :::
::: /F(+) \Source\Folder-to search for files. Default is current folder.     :::
:::       /f will search recursively but discard folder info for Copy/Move.  :::
:::       If /f+ is used folder is searched recursively for given files and  :::
:::       any relative folders will be rebuilt for Copy or Move operations.  :::
:::       Use /f- to perform a non-recursive search for video files.         :::
:::       Default: Current Folder/Recursive Search                           :::
::: /C(+) \Copy\To\Folder-destination for Matched/Renamed files. If omitted  :::
:::       and /r is used, files are Renamed in place. /c- Moves files        :::
:::       instead of Copying them. If /f+ is used recursive folders will be  :::
:::       rebuilt in \Copy\To\Folder. If /f is used the search is still      :::
:::       recursive, but the relative folder structure is ignored.           :::
:::       Default: Do Not Copy or Move files                                 :::
::: /S(+) Column#-will sort the CSV using the decimal number column#,        :::
:::       and then export it to %log%_Sorted#.csv before matching files.     :::
:::       If /s- is used columns will be sorted in reverse order.            :::
:::       Columns may be sorted numerically by setting them in the varible   :::
:::       "numeric= 1 4 5 6 7 8 ". Decimals only; delimited by spaces.       :::
:::       /I may be used for a much slower non-destructive native-batch sort.:::
:::       Default: Don't Sort                                                :::
::: /X    SearchExt-is a string containing one or more file extensions to    :::
:::       search for. Default is a list of known video file extensions.      :::
:::       Default: "3gp asf avchd avi cam divx fla flv m1v m2v m4v mkv       :::
:::                 mng mov mp4 mpg mpeg nsv ogv rm svi ts vob wmv"          :::
::: /M(+) MatchTemplate-is a string representing which column(s) to match    :::
:::       the source filenames against. Columns from the CSV are enumerated  :::
:::       as "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ". 1 is the first column   :::
:::       of the CSV and 0 is the leading-zero decimal index position of the :::
:::       row in the CSV (after sorting). If only one column is specified    :::
:::       the source filename must match the CSV entry exactly, except case. :::
:::       If more than one column is specified then the source filename must :::
:::       match all of those columns in the CSV. If omitted then files are   :::
:::       matched against the actual filesizes from the first column of the  :::
:::       CSV. /m+ will force matching using both filenames and filesizes.   :::
:::       Default: Match Files by FileSize Only                              :::
::: /R(+) RenameTemplate-is a string representing the new names for matched  :::
:::       files. Columns are enumerated as above and referenced in the       :::
:::       Template as /0/1/2../x/y/z, with the contents of said column being :::
:::       substituted for the slash-and-columnID into the target filename.   :::
:::       You may also use standard batch script file info in RenameTemplate :::
:::       by using a backslash: \d \f \s \p \ps \n \ns \x \xs \a \t \z.      :::
:::       /r+ will instead use the template to create a folder in the target :::
:::       directory and move the file into it with the filename unaltered.   :::
:::       Default: Use Same FileName as Source/Don't Rename Files            :::
::: /O(+) This switch will set Copy/Move operations to overwrite files in    :::
:::       target folder. /o- will skip all instead. If /o+ or omitted the    :::
:::       choice is given at runtime to Skip/Overwrite/SkipAll if needed.    :::
:::       Default: Ask at Runtime                                            :::
::: /U(+) This switch will create a new CSV named %log%_Unmatched.csv that   :::
:::       contains info for all discovered files that did not match the CSV. :::
:::       /u+ will use MediaInfo.exe (if found) to provide additional data,  :::
:::       otherwise just FileSize:FileName:Ext is included in the new CSV.   :::
:::       Default: Do Not Create %log%_Unmatched.csv                         :::
::: /D(+) Column#-will check CSV for duplicate entries by Column#. Use this  :::
:::       to ensure that FileSizes, FileNames, etc are unique so you can     :::
:::       accurately match renamed files. /d+ for a case-sensitive check.    :::
:::       Default: Don't Perform Duplicate Check                             :::
::: /G(+) Column# String-will check Column# in each matched entry and only   :::
:::       "Grab" those containing %String%. You may separate entries in      :::
:::       %String% with the delimeter(default is :). Affects Copy/Move/Rename:::
:::       /g 9 "Edge Hero" matches ANY NewName (9) containing "Edge Hero"    :::
:::       /g+ 11 2014:06- must match ALL and yields entries from June 2014   :::
:::       /g- 12 aud:vis must match NONE and yields entries w/o audBM/visBM  :::
:::       Default: Grab Everything/No Restrictions                           :::
::: /A    Special interest addition for myself. Will match .JPGs, .PNGs and  :::
:::       Previews for each video and Copy/Move/Rename them as well.         :::
:::       Used with Markster's MovieSheets+ PlugIn Menu for the WDlxTV Live. :::
:::       Default: Ignore All .JPG, .PNG, and Preview Files                  :::
:::                                                                          :::
::: Examples:                                                                :::
::: CHFR.cmd /F "D:\Cock Hero" /U                                            :::
::: Will compare all video files in folder "D:\Cock Hero" by size against    :::
::: the internal CSV and produce "Unmatched.csv" containing "Size:Name:Ext"  :::
::: for files not found in the CSV. Will also produce the file "Needed.csv"  :::
::: which lists info for all files in the CSV not found in "D:\Cock Hero".   :::
::: If any of these lists are empty, the file will be deleted upon exit.     :::
:::                                                                          :::
::: CHFR.cmd /L CHFR_Needed.csv /F+ e:\ /C- "d:\Cock Hero\"                  :::
::: Will load the latest "Needed" list as CSV and recursively search the     :::
::: entire "e:\" drive for matching files. Any matched files will then be    :::
::: moved (/C-) with folders (/F+) to the target "d:\Cock Hero\". All actions:::
::: like Copy/Move/Rename are recorded to the log file "Logfile.txt". As     :::
::: always, all entries without matching files are written to "Needed.csv".  :::
:::                                                                          :::
::: CHFR.cmd /r "/0 - /9" /s 11 /x "avi mp4 mov"                             :::
::: Will match all *.avi, *.mp4, and *.mov files in the current folder       :::
::: against the internal CSV by filesize after first sorting the DataBase by :::
::: column#11 (Release Date). It will then rename all matched files like so: :::
::: "%Column0% - %Column9%", which would be "001 - Cock Hero 01 Amateur".    :::
:::                                                                          :::
::: CHFR.cmd /f g:\ch\704x400\ /c H:\XXX\CH\ /m 2 /r "/A_/B_/9_/8p [/4][/2]" :::
::: Will recursively search "g:\ch\704x400" for all video files and attempt  :::
::: to match filenames exactly against Column#2 (Original FileName). Any     :::
::: matching files are copied to "H:\XXX\CH" and are renamed as so:          :::
::: "%Column10%_%Column11%_%Column9%_%Column8%p [%Column4%][%Column2%]" or   :::
::: %Creator%_%ReleaseDate%_%NewName%_%Height%p [%Duration%][%OriginalName%] :::
::: or "lalaland_2009-02-02_Cock Hero 01 Amateur_418p [15m47s][Cock Hero 1]" :::
::: This command was used after re-encoding the entire collection to copy    :::
::: the videos on an external drive and rename them for easy viewing. Nice!  :::
:::                                                                          :::
::: CHFR.cmd /F H:\XXX\CH /R /2 /M 24a9 /C- "H:\Cock Hero"                   :::
::: Will rename all of the videos copied in the previous operation back to   :::
::: their Original Filenames by matching the current names against Columns   :::
::: 2, 4, 10, and 9. Current filename must contain all columns to match.     :::
::: H:\XXX\CH is searched recursively (/f), but all files are moved to       :::
::: "H:\Cock Hero" (/c-) without retaining recursive folders (/f).           :::
:::                                                                          :::
::: CHFR.cmd /L+ noBM.csv /F g:\CH\ /U+ /M+ 2                                :::
::: Will load the internal CSV (if it exists) and then append the contents   :::
::: of the CSV file "noBM.csv" to the database. The folder "g:\CH\" is       :::
::: recursively searched and files are matched both by filesize and by exact :::
::: match of the filename against Column#2 (Original Filename). If MediaInfo :::
::: is found (/u+), extended file info is written to Unmatched.csv. I use    :::
::: this command to update my CSVs after downloading new videos to the set.  :::
::: "noBM.csv" contains info for PMVs that are Cock Hero-ish in nature.      :::
:::                                                                          :::
::: CHFR.cmd /l Unsorted.csv /s 9 /i a /i b                                  :::
::: Will load an unsorted CSV instead of the internal one (/l) then sort it  :::
::: by Column#9 (NewName) using a fast and destructive sort (/s), producing  :::
::: "Sorted#9_NewName.csv". Then the CSV is sorted by Column#10 (Creator)    :::
::: using a very slow, but non-destructive, native-batch insert sort (/i)    :::
::: producing "Sorted#10_Creator.csv". Finally, the CSV is slow-sorted using :::
::: Column#11 (ReleaseDate) to produce "Sorted#11_ReleaseDate.csv". This is  :::
::: the manner used to sort the internal CSV prior to releasing CHFR.cmd.    :::
::: /S 9 /I- 11 /I 10 sort the CSV by Creator; most recent release; NewName  :::
:::                                                                          :::
::: CHFR.cmd /L- /F C:\PMV /U+                                               :::
::: CHFR.cmd /l CHFR_Unmatched.csv /f+ c:\pmv /c- c:\pmv\HQ /g 8 720:1080    :::
::: 1st command will skip loading a CSV (/l-), set source folder as "C:\PMV" :::
::: and recursively search (/f) for all video files, producing a CSV file    :::
::: "Unmatched.csv" containing 8 columns of info for each video found (/u+). :::
::: 2nd command will load the CSV created by the previous command (/l), set  :::
::: the source folder to search recursively and retain folder info (/f+),    :::
::: then move matching files to the folder "C:\pmv\HQ" (/c-), but only grab  :::
::: them (/g) if the 8th column (Height) contains either the string "720" or :::
::: "1080". An easy method of separating large groups of videos by criteria. :::
::: /G- 8 720:1080:1920 will move everything BUT the high-quality videos.    :::
::: /G+ 9 "Cock Hero:Flux" moves entries containing both Strings in NewName. :::
:::                                                                          :::
::: CHFR.cmd /f D: /c "E:\BitTorrent\Cock Hero" /r+ /a[/b]/9[/4]/c           :::
::: Will recursively search the entire D:\ drive ignoring relative folders   :::
::: (/f) and Copy (/c) any matching files to a sub-directory of the target   :::
::: folder "E:\BitTorrent\Cock Hero" following the template "/a[/b]/9[/4]/c".:::
::: This type of command will be used to built the torrent collection.       :::
:::                                                                          :::
::: CHFR.cmd                                                                 :::
::: Will display a brief overview of options if no parameters are given.     :::
:::                                                                          :::
::: Notes:                                                                   :::
::: All copy, move, and rename activity is logged to "%log%_Logfile.txt".    :::
::: All produced text files are named after the last CSV loaded, or %SELF%.  :::
::: All text files are overwritten each time CHFR is ran, except the Logfile.:::
::: The minimum CSV size accepted (& produced) is a header 3 columns wide.   :::
::: /U+ use MediaInfo.exe and "Unmatched.csv" will include extra video info. :::
::: All internal/external CSV files must begin with a header as the 1st line.:::
::: Number of columns in Database is determined by the amount in the header. :::
::: Empty CSV entries are not allowed! The script will give warning and stop.:::
::: /D,/S will default to 1,2 if last on commandline and parameter omitted.  :::
:::                                                                          :::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::: Created by CirothUngol for the Milovana Forums             April 4, 2015 :::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::