# vbs or bat file copy / rename based on txt file in that directory



## usmc-ratman (Aug 6, 2004)

Structure:
 I have a network directory that stores photos of individuals in jpg format. There may be only 2 pics of each person, or there may be 7 pics.
 Each persons pics are stored in a randomly named directory / subdirectory. dont have any control over the original program, it's just the way it was written, does not seem to follow any logical pattern, possibly a HEX naming structure based off the date & time, who knows (I will include a sample directory tree at the end of the post).
 Included within each of these created directories, along with the pictures, is a standard text file (filename "B.TXT") which includes the date the picture was taken, the persons name, and other information.
 Each time a person comes in and their picture is taken, the program: (i) creates the random directory (ii) stores the pics (iii) creates the "B.TXT" file with the persons information (iv) generates several other program specific files that I have no need for.
 The program names each of the pictures with the exact same names, which is why they are stored in different directories, so they will not overwrite. The retention period on each individuals directory, pics and files is approximately 40 days.

MFXX0000.jpg (Forward facing)
MLXX0000.jpg (Left facing)
MRXX0000.jpg (Right facing)
STXX0000.jpg (Identifying marks picture 1)
STXX0001.jpg (Identifying marks picture 2)

  As stated above, sometimes there is only the MFXX0000.jpg and MRXX0000.jpg files, but sometimes there is forward, left, right, and multiple STXX files.

Problem:
I have created a simple batch file with a robocopy command that copies just the jpg and b.txt files and saves them to a desktop computer, this of course, recreates the directory structure as well. I retain the b.txt file so that I will have the persons name and other information to go with the pictures. At least this way I can goto the root directory of the many random subdirectories, and run a search through windows explorer of the "B.TXT" files, searching for the text string of the persons name.
What I am trying to figure out is a simple batch file or script that will do the following:

Search through the root picture directory and sub-directories
Search the "B.TXT" file in each sub-directory for the text that follows the string "NAM = ", store this variable as $NAM
Search the "B.TXT" file in each sub-directory for the text that follows the string "DOE = ", store this variable as $DATE
Rename the MFXX0000.jpg file to "$NAM_$DATE_MFXX_##" (## being sequentially numbered files depending on how many pictures are in that particular directory)
Rename the MRXX0000.jpg file to "$NAM_$DATE_MRXX_##"
Rename the MLXX0000.jpg file to "$NAM_$DATE_MLXX_##"
Rename the STXX0000.jpg file to "$NAM_$DATE_STXX_##"

After this is done, then I can do another simple search for *.jpg files, using windows explorer search, and drag and drop them all into a single directory, and there should not be any duplicate file names.
Currently there are 617 pictures, however there are 617 files named "MFXX0000.jpg", 617 files named "MRXX0000.jpg", and so on.
The move to a single directory for all .jpg files could also be incorporated into the script or batch file, but that issue, once they are renamed, is a simple enough manual fix if need be.

Anyone have any ideas. There are programs out there that will recurse subdirectories, copying and renaming all files and depositing them in a single directory, but none that will search for specific strings within each directory's text file with the naming properties.

=-=-=-=-=-=- STRUCTURE OF THE "B.TXT" FILE STRINGS INFORMATION -=-=-=-=-=-=-=-

NAM = "BLOE,JOE SMITH" <<------ need this as the first stored variable
SEX = "M" 
RAC = "W" 
DOB = "03021984" 
HGT = "602" 
WGT = "170" 
EYE = "BRO" 
HAI = "BRO" 
DOE = "20110310" <<------- need this as the second stored variable
IDX_JPG = "MFXX0000.jpg" 
IMT = "FACE" 
PHD = "20110310" 
HLL = "480" 
VLL = "600" 
CGA = "JPEGB" 
CSP = "YCC" 
POS = "F"

=-=-=-=-=-=- EXAMPLE OF JACKED UP DIRECTORY STRUCTURE CREATED BY THE PROGRAM -=-=-=-=-=-=-=-

Folder PATH listing for volume DigitalArchive
Volume serial number is 00500055 0658:AEB1
P:.
\t000
\..\t061
\..\t07e
\..\t0da
\..\t0f3
\..\t0fb
\..\t0c7
\t001
\..\t067
\..\t0d7
\..\t08e
\..\t09d
\..\t08c
\t002
\..\t001
\..\t08e
\..\t041
\t004
\..\t00c
\..\t09f
\..\t0a4
\..\t081

thanks in advance for anyone taking on this puzzle 
Respectfully submitted,
John R.

*~-~-~-~ techguy forums are the greatest ~-~-~-~*


----------



## usmc-ratman (Aug 6, 2004)

Wow, no takers yet ? I see there has been a few lookers, but no one  - just a bump on the thread to get another look

many thanks to anyone that will give me a hand


----------

