I’ve been doing some research but unfortunately I’m just too much of a novice to tackle this on my own, so I’m seeking your guidance, scripting dopers. I think this is a relatively simple script, but that just goes to show you how helpless I really am. Here’s what I need.
I get images delivered to me in folders, each folder having a name as follows
Node 0013
Node 2172
Node 1024
Node 0839
etc…
Note that the serial number for each node is always 4 digits long, with leading 0’s if necessary
Within each folder are **several **jpeg images with long complicated names that I change and move, but I only do this to the **last **image in each Node folder, the other images are just completely ignored (only one picture per folder is renamed and moved, and it’s always the last picture in the Node folder).
If you read my last thread, I change them to something like 18003222_dep.jpg, based on a value called Rec_ID that is captioned in each image. Well, with free OCR as unreliable as it is, I couldn’t get a script working to reliably read these values. However, I’ve come up with another solution! Each Node value matches up with a corresponding Rec_ID value, which I have in tab delimited ‘rec_id.txt’ file that I’ve been able to obtain that looks like this:
Serial Rec_ID
0013 18003222
1024 18003244
etc…
So, what I need to do is set up a script to run from the folder where all the Node directories are that will do essentially the following:
1)Get the serial value from a ‘Node ####’ folder (get rid of the Node part and keep just the ####, store as a variable SERIAL I guess)
2)search the ‘rec_id.txt’ file for the matching serial number (go line by line, store each serial value as a temporary variable, check to see if SERIAL = TEMP_SERIAL, if so then do the following
- store REC_ID value as a variable
4)Copy ONLY the last .jpg file (when sorted by date or by name, either works for these images) in the ‘Node SERIAL’ directory to a new file called REC_ID +"_dep.jpg"
-
Move the REC_ID_dep.jpg image up one level to where the batch script will be running from. (this can probably just be done in step 4 actually)
-
repeat for the next Node #### folder, until all the folders have been searched.
The final result should be that I have 1 jpeg from each Node #### folder now sitting in the directory where the script ran from, with the proper name.
A windows batch script would be ideal, but a linux bash script solution would also work if that’s your specialty.
Thank you so much in advance for any and all assistance. Even if all you have are resources for me to look stuff up, or hints, or whatever, I’d greatly appreciate it. I know I’m going to have to use some FOR loops but I’m not sure exactly what arguments/commands to pass them and how to parse what I need to parse. I also have no idea how to get values from a text file like I need to do.