List Info

Thread: rename file based on file's timestamp




rename file based on file's timestamp
country flaguser name
Australia
2007-10-24 07:45:08
Hi,

Hopefully, a simple request...

I have a series of files in a directory:

-rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 28  2006
209.mp3
-rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 31  2006
212.mp3
-rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  1  2006
213.mp3
-rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  2  2006
214.mp3
-rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  3  2006
215.mp3

etc.

Now I want to rename these so the new filenames are based on
the file's
timestamp, like so:

-rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 28  2006
2006-07-28.mp3
-rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 31  2006
2006-07-31.mp3
-rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  1  2006
2006-08-01.mp3
-rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  2  2006
2006-08-02.mp3
-rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  3  2006
2006-08-03.mp3

I can write some Python code to do this, but maybe there is
another way,
perhaps using a shell script.  Any thoughts?

Thanks,

Regards
Andrew
_______________________________________________
freebsd-questionsfreebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-que
stions
To unsubscribe, send any mail to
"freebsd-questions-unsubscribefreebsd.org"

Re: rename file based on file's timestamp
country flaguser name
Germany
2007-10-24 08:07:04
Am Mittwoch, 24. Oktober 2007 14:45:08 schrieb andrew
clarke:
> Now I want to rename these so the new filenames are
based on the file's
> timestamp, like so:
>
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 28 
2006 2006-07-28.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 31 
2006 2006-07-31.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  1 
2006 2006-08-01.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  2 
2006 2006-08-02.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  3 
2006 2006-08-03.mp3
>
> I can write some Python code to do this, but maybe
there is another way,
> perhaps using a shell script.  Any thoughts?

Simple bash script to do this (untested):

for i in $*
do
	mv $i `stat -f %Sm -t %Y-%m-%d`.mp3
done

HTH!

-- 
Heiko Wundram
Product & Application Development
_______________________________________________
freebsd-questionsfreebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-que
stions
To unsubscribe, send any mail to
"freebsd-questions-unsubscribefreebsd.org"

Re: rename file based on file's timestamp
country flaguser name
Switzerland
2007-10-24 09:26:32
Heiko Wundram (Beenic) wrote:
> Am Mittwoch, 24. Oktober 2007 14:45:08 schrieb andrew
clarke:
>> Now I want to rename these so the new filenames are
based on the file's
>> timestamp, like so:
>>
>> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 28 
2006 2006-07-28.mp3
>> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 31 
2006 2006-07-31.mp3
>> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  1 
2006 2006-08-01.mp3
>> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  2 
2006 2006-08-02.mp3
>> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  3 
2006 2006-08-03.mp3
>>
>> I can write some Python code to do this, but maybe
there is another way,
>> perhaps using a shell script.  Any thoughts?
> 
> Simple bash script to do this (untested):
> 
> for i in $*
> do
> 	mv $i `stat -f %Sm -t %Y-%m-%d`.mp3
> done

just pay attention at the situation when two files have the
same timestamp..

> 
> HTH!
> 


-- 
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp
_______________________________________________
freebsd-questionsfreebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-que
stions
To unsubscribe, send any mail to
"freebsd-questions-unsubscribefreebsd.org"

Re: rename file based on file's timestamp
country flaguser name
United States
2007-10-24 11:04:37
On Wed, Oct 24, 2007 at 10:45:08PM +1000, andrew clarke
wrote:

> Hi,
> 
> Hopefully, a simple request...
> 
> I have a series of files in a directory:
> 
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 28 
2006 209.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 31 
2006 212.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  1 
2006 213.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  2 
2006 214.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  3 
2006 215.mp3
> 
> etc.
> 
> Now I want to rename these so the new filenames are
based on the file's
> timestamp, like so:
> 
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 28 
2006 2006-07-28.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Jul 31 
2006 2006-07-31.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  1 
2006 2006-08-01.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  2 
2006 2006-08-02.mp3
> -rw-r--r--  1 ozzmosis  ozzmosis  115201253 Aug  3 
2006 2006-08-03.mp3
> 
> I can write some Python code to do this, but maybe
there is another way,
> perhaps using a shell script.  Any thoughts?

A script is a script whether it is in Python, Perl or one of
the common
shells.   Use what works for you.  I'd use Perl, but I am
already
somewhat familiar with Perl.

////jerry

> 
> Thanks,
> 
> Regards
> Andrew
> _______________________________________________
> freebsd-questionsfreebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-que
stions
> To unsubscribe, send any mail to
"freebsd-questions-unsubscribefreebsd.org"
_______________________________________________
freebsd-questionsfreebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-que
stions
To unsubscribe, send any mail to
"freebsd-questions-unsubscribefreebsd.org"

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )