Page 1 of 1
Renaming script after downloading
Posted: September 12th, 2012, 1:13 pm
by svendaems
Hello
I'm trying to rename the folders that I've downloaded by adding a date-time stamp.
I've following script
Code: Select all
#!/bin/sh
mv -f $1 "date +%Y-%m-%d %H:%M:%S $1"
When I download a test file, I get following error
Exit(1) mv: can’t rename ’/volume1/Downloads/test’: No such file or directory
Any idea?
Re: Renaming script after downloading
Posted: September 12th, 2012, 1:58 pm
by shypike
I suppose you are new to scripting?
First of all $1 is the full path of the folder, so /aaaa/bbb/ccc/name.
Next, you need to add quotes. The date command doen't work like you're using it.
What you're probably after is something like this:
Code: Select all
#!/bin/sh
# go to folder
cd "$1"
# go one down
cd ..
# Create date stamp, careful: there are single quotes and back-ticks!
MYDATE=`date '+%Y-%m-%d %H:%M:%S'`
# rename, where $3 is the plain name without the full path
mv "$3" "$MYDATE $3"
Re: Renaming script after downloading
Posted: September 12th, 2012, 2:55 pm
by svendaems
Yes, I'm quite new to it ;-)
But I want to rename the complete folder where it was downloaded in, not only the file. I've added the quotes but still the same error
Code: Select all
#!/bin/sh
mv -f "$1" "date +%Y-%m-%d %H:%M:%S $1"
mv: can't rename '/volume1/Downloads/test': No such file or directory
Re: Renaming script after downloading
Posted: September 12th, 2012, 2:59 pm
by shypike
What you want is impossible, you cannot put the date ahead of /volume1.
The first place where you can start is after /volume1/Downloads.
Also you're still using the date command wrong.
Re: Renaming script after downloading
Posted: September 13th, 2012, 7:35 am
by svendaems
super, it works, thank you very much!