-
All replies
-
Helpful answers
-
-
Nov 4, 2015 6:25 AM in response to vnylundby Tony T1,vnylund wrote:
Please see attached screenshot of the first lines in the .csv file.
Need to see how it looks in plain text (not excel).
Can you open the file with TextEdit and then post a few lines?
-
Nov 4, 2015 6:28 AM in response to Tony T1by vnylund,Sorry about my mistake!
Attached is a screenshot of the text in TextEdit and following are lines directly copy pasted:
OldImageName;NewImageName
0256_027.jpg;0256027L.jpg
0283_3KH.jpg;PI02833KHL.jpg
0283_3KH.jpg;PI02833KHM.jpg
0283_3RH.jpg;PI02833RHS.jpg
05DPP036_SM_PD22_n1z1.jpg;Y41R98070.jpg
0705_4RF.jpg;07054RFM.jpg
0705_4RF.jpg;07054RFS.jpg
0705_4RF.jpg;07054RFXL.jpg
0705_4RF.jpg;07054RFXXL.jpg
0711_3RH.JPG;PI07113RHXL.jpg
0877_3YY.jpg;PI08773YYM.jpg
0991706 GEL BLOCK.jpg;EL0991706.jpg
11111029-31._BibTight Elite AmFIB_Blk_2010.jpg;PI11111031021M.jpg
11111029-31._BibTight Elite AmFIB_Blk_2010.jpg;PI11111031021XL.jpg
11111032021.jpg;11111032021L.jpg
11111032021.jpg;11111032021M.jpg
11111033-35._BibTight El. Th.Fleece_Blk_2010.jpg;PI11111035021M.jpg
11111037._Pant Sel. Barrier WXB_Blk_2010.jpg;PI11111037021L.jpg
11111037._Pant Sel. Barrier WXB_Blk_2010.jpg;PI11111037021S.jpg
11111037._Pant Sel. Barrier WXB_Blk_2010.jpg;PI11111037021XL.jpg
-
Nov 4, 2015 7:36 AM in response to vnylundby Tony T1,ok, I see the problem.
The names are separated with ; not ,
In the script:
change:
OldImageName=${line%,*}
NewImageName=${line#*,}
to:
OldImageName=${line%;*}
NewImageName=${line#*;}
-
-
Nov 4, 2015 8:16 AM in response to vnylundby Tony T1,I tested it and it should be working.
Lets try something simple.
Save a portion of the CSV file to the Desktop and name it Untitled.csv
Then create an Automator Workflow with this one Run Shell Script Action:
cd ~/Desktop
while read line
do
OldImageName=${line%;*}
NewImageName=${line#*;}
echo mv "$OldImageName" "$NewImageName"
done <"Untitled.csv"
Then run the workflow, you should see in the [Results] window the command that would be run (if echo was removed):
Now, if you see this when you run it, remove echo from the script (so it reads: mv "$OldImageName" "$NewImageName") then copy a few of the image files to the Desktop and run the Workflow again (the image files on the Desktop should be renamed)
-
Nov 4, 2015 3:22 PM in response to vnylundby williamleon,I Had the same problem where the script would run without error but with no changes to my image names - due to my immediate need I ended up going to out source website (upwork) and hired a guy to write the script exactly as I needed and then email it to me. I have run it 6 times renaming 500 images each time - without error. I would love to learn to write the script but this time I took the easier way - although more expensive - cost me $60US but in this case well worth it. Good luck
-
-
Nov 5, 2015 5:25 AM in response to vnylundby Tony T1,That is strange. It works when I tested on the data in your file.
I wonder what you would get if you just tried to print the lines in the file.
Try this:
cd ~/Desktop
while read line
do
echo $line
done <"Untitled.csv"
-
Nov 5, 2015 5:31 AM in response to Tony T1by vnylund,Tony,
Same thing again, runs script and no results...
-
Nov 5, 2015 6:33 AM in response to vnylundby Tony T1,And this is a plain text file? (In TextEdit Format->Make Plain Text)
-
Nov 5, 2015 9:52 AM in response to vnylundby Tony T1,vnylund wrote:
Same thing again, runs script and no results...
It's possible that Excel is saving the CSV with CR line ends.
Lets try to convert from CR to LF with tr
Try this with samples of the images to be renamed on the Desktop
Use the original CSV file you have (rename "Untitled" in script)
(the CR line feeds are saved to "Untitled.csv.tmp", then when the script completes, the tmp file is deleted)
cd ~/Desktop
tr '\r' '\n' < "Untitled.csv" > "Untitled.csv.tmp"
while read line
do
OldImageName=${line%;*}
NewImageName=${line#*;}
mv "$OldImageName" "$NewImageName"
done < "Untitled.csv.tmp"
rm "Untitled.csv.tmp"
-
Nov 9, 2015 6:13 AM in response to Tony T1by vnylund,Hi Tony!
Sorry for the lack of response here but I've been away for a few days.
I tried the script and this time it actually felt like something happened since it took a few seconds for the script to run. And the .tmp file showed on the desktop for a little while as well before it disappeared.
What's the next step?
Edit: I realized that I didn't place any images on the desktop so I did it again and it worked !!!!!! One image didn't get renamed though but I'll check if there's something wrong in the .csv file. But as for now I hope it will work.
Edit#2: The script didn't process the last line in the .csv file so I just added a "dummy line" at the bottom and it renamed the last image as well.
Thank you very much Tony!!!
-
Nov 9, 2015 6:27 AM in response to vnylundby Tony T1,vnylund wrote:
Hi Tony!
Edit: I realized that I didn't place any images on the desktop so I did it again and it worked !!!!!! One image didn't get renamed though but I'll check if there's something wrong in the .csv file. But as for now I hope it will work.
Edit#2: The script didn't process the last line in the .csv file so I just added a "dummy line" at the bottom and it renamed the last image as well.
Thank you very much Tony!!!
Great. Sorry it took so long for me to remember that Microsoft uses CR
BTW, you can add the "dummy line" to the tmp file with the script by adding: echo >> Untitled.csv.tmp
cd ~/Desktop
tr '\r' '\n' < "Untitled.csv" > "Untitled.csv.tmp"
echo >> Untitled.csv.tmp
while read line
do
OldImageName=${line%;*}
NewImageName=${line#*;}
mv "$OldImageName" "$NewImageName"
done < "Untitled.csv.tmp"
rm "Untitled.csv.tmp"
-
Nov 9, 2015 7:20 AM in response to Tony T1by vnylund,Worked beautifully!
Again thank you very much Tony! I really appreciate your help and it makes things a lot easier for me!!!






