Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,374 Programmers. There are 1,424 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

one-liner to rename a file

 
Reply to this topicStart new topic

one-liner to rename a file

beef
post 10 Apr, 2008 - 12:03 PM
Post #1


D.I.C Head

Group Icon
Joined: 2 Nov, 2006
Posts: 128



I need a little help with a one-liner I'm trying to use. I want to rename a file with a date stamp (ex test.txt renamed to test-04-10-08.txt)

Here's what I'm trying right now.
CODE
perl -e rename('test.txt','test-' . ((localtime)[4]+1900) . '-' . ((localtime)[3]+1) . '-' . ((localtime)[5]) . '.txt');


suggestions?
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


KevinADC
post 10 Apr, 2008 - 12:31 PM
Post #2


D.I.C Head

Group Icon
Joined: 23 Jan, 2007
Posts: 168

I believe you have to put quotes around the code part after the -e switch. If you are on Linux or Unix change all the single-quotes to double-quotes and wrap the code in single-quotes:

-e ' print "$foo\n";'

its the opposite with Windows

-e " print \"$foo\n\";"

or use qq to avoid the escapes:

-e " print qq{$foo\n};"
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

beef
post 10 Apr, 2008 - 12:51 PM
Post #3


D.I.C Head

Group Icon
Joined: 2 Nov, 2006
Posts: 128

That did it, thanks for your help.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 02:47AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month