-
All replies
-
Helpful answers
-
-
Feb 8, 2016 12:55 PM in response to jorrflvby Tony T1,jorrflv wrote:
Tony, You seem to be giving a lot of help here and I appreciate that. I am trying to do something similar with pdf files, but I am not getting errors, nor are my file names changing.
Do you see anything wrong with the code?
First lets see that the csv file has the correct line endings.
Create a test csv file with TextEdit in Plain Text (TextEdit->Format->Make Plain Text).
Type a few lines in by hand (don't cut-n-paste) and then run the workflow selecting this csv file.
(If it is a problem with the line endings, then we can add a line to the script to do a conversion)
If it still is not working, lets debug with "echo":
add: echo before cp and mv and then at the end of each line add: >> $HOME/Desktop/debug.txt
This will create a file on the Desktop showing us what is (or is not) happening
-
-
Feb 8, 2016 1:42 PM in response to jorrflvby Tony T1,jorrflv wrote:
I tried new .csv file it was same results. I tried adding the echo command and I am not getting any debug files. Should look like this?
Need to add >> before $HOME (this redirects stdout to a file):
>> $HOME/Desktop/debug.txt
Also, it should not matter, but remove the white space in the script:
cd "$1"
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
echo cp "$OldImageName" "~/Documents/$NewImageName" >> $HOME/Desktop/debug.txt
echo mv "$OldImageName" "$NewImageName" >> $HOME/Desktop/debug.txt
done < "$2"
And post a few line of the csv file so that I can test it on my end
-
Feb 8, 2016 1:59 PM in response to Tony T1by jorrflv,Here are the sample csv lines:
OldImageName,NewImageName
Student1.pdf,Aizenberg_Samuel_0028
Student2.pdf,Alexander_Pierce_0024
Here are the results of the debug.txt file
cp OldImageName /Users/orrj/Documents/NewImageName
mv OldImageName NewImageName
cp Student1.pdf /Users/orrj/Documents/Aizenberg_Samuel_0028
mv Student1.pdf Aizenberg_Samuel_0028
-
Feb 8, 2016 2:25 PM in response to jorrflvby Tony T1,ok, so it looks like it's not finding the file (it looks like it's not changing to the directory with the file)
First, remove the debug (echo and >> $HOME/Desktop/debug.txt)
Now, lets try the command by hand in Terminal:
Open Terminal (Applications/Utilities/Terminal)
cd to the Folder with the files (enter cd and then the folder name and then press enter.)
You should see the folder name in the command prompt.
For example, when I cd to Documents, I see: MacBook-Air:~/Documents Tony$
(You can get a list of the directory by entering ls)
When you are sure you changed to the correct directory:
Copy the commands that's in the debug.txt file and paste into the Terminal Window:
cp Student1.pdf /Users/orrj/Documents/Aizenberg_Samuel_0028
and
mv Student1.pdf Aizenberg_Samuel_0028
If these copy and move as expected, then lets debug the cd command:
Add echo to the 1st line:
echo cd "$1" > $HOME/Desktop/debug.txt
(note: the single > will overwrite the existing debug.txt file)
-
Feb 8, 2016 2:47 PM in response to Tony T1by jorrflv,I am trying to follow the bash script, but I can see right now that there will be an issue because the folders are on my desktop not in my documents folder... that would make a difference yes?
-
Feb 8, 2016 2:55 PM in response to jorrflvby Tony T1,jorrflv wrote:
I am trying to follow the bash script, but I can see right now that there will be an issue because the folders are on my desktop not in my documents folder... that would make a difference yes?
Should not make a difference.
The first action selects the Folder that has the files.
Now that I think about it, there is no need to debug the cd.
Run the Workflow Again (with no echo commands), then when it completes, click the [Results] box and you'll see the directory that the workflow is changing to:
In this example, I selected the Untitled Folder on my Desktop:
When you click [Results] you should see the folder with the files
-
Feb 8, 2016 3:30 PM in response to Tony T1by jorrflv,awesome... The first line went.. Now when I try my other CSV file with the whole batch it is not moving on to the next record. none of the other files are renamed.
Jon -
Feb 8, 2016 3:48 PM in response to jorrflvby Tony T1,jorrflv wrote:
awesome... The first line went.. Now when I try my other CSV file with the whole batch it is not moving on to the next record. none of the other files are renamed.
Jonok, then that means that we need to convert the line ends.
How was the CSV file created? (i.e was it from an excel file?)
I'm going to guess that there are carriage returns in the file that needs to be removed.
Add this line: NewImageName=${NewImageName//$'\r'}
So the script should be:
cd "$1"
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
NewImageName=${NewImageName//$'\r'}
cp "$OldImageName" "~/Documents/$NewImageName"
mv "$OldImageName" "$NewImageName
done < "$2"
If this does not work, then we need to see what the line ends look like, so open Terminal, enter cat -e then space then drag the CSV file to the Terminal Window and press enter and then post a few lines.
-
Feb 8, 2016 4:27 PM in response to Tony T1by jorrflv,added the line no go... here are the results of terminal command
OldImageName,NewImageName^MStudent1.pdf,Aizenberg_Samuel_0028^MStudent2.pdf,Alex ander_Pierce_0024^MStudent3.pdf,Anderson_Eric_8583^MStudent4.pdf,Apalategui_Aime e_7987^MStudent5.pdf,Attanasio_Nia_7722^MStudent6.pdf,Ayoub-Butcher_Angelina_009 9^MStudent7.pdf,Badger_Gage_7751^M
-
Feb 8, 2016 4:28 PM in response to jorrflvby jorrflv,Fyi I had to SUDO to make the command work. is that normal? or could that be the problem as well?
-
Feb 8, 2016 4:59 PM in response to jorrflvby Tony T1,jorrflv wrote:
added the line no go... here are the results of terminal command
OldImageName,NewImageName^MStudent1.pdf,Aizenberg_Samuel_0028^MStudent2.pdf,Alex ander_Pierce_0024^MStudent3.pdf,Anderson_Eric_8583^MStudent4.pdf,Apalategui_Aim e e_7987^MStudent5.pdf,Attanasio_Nia_7722^MStudent6.pdf,Ayoub-Butcher_Angelina_00 9 9^MStudent7.pdf,Badger_Gage_7751^M
Looks like just a CR (my guess was CRLF)
This should work (translates CR to LF to file.tmp then deletes the tmp file when done):
cd "$1"
tr '\r' '\n' < "$2" > ~/Desktop/file.tmp
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
cp "$OldImageName" "~/Documents/$NewImageName"
mv "$OldImageName" "$NewImageName
done < ~/Desktop/file.tmp
rm ~/Desktop/file.tmp
-
Feb 8, 2016 5:10 PM in response to Tony T1by jorrflv,Bingo! Got it..... Wow I would have never worked through that without your willingness to help.... This will be extremely helpful for me.
Jon
-



