Solved

RENAME or REN with a date and time stamp

Posted on 2003-11-17
7
2,777 Views
Last Modified: 2010-05-18
Hi -

I am using WS_FTP PRO which allows for executing a Dos script.  Can I use the REN or RENAME command to append the system date and time to the end of the filename I am downloading.

REN file1.txt file1.11172003134700.txt


Thanks
0
Comment
Question by:mtgcpc
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 9767716
mtgcpc,
How about copy filename +/b
This will update the time stamp to the current
~sirbounty
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 9767749
Oops - I now understand what you're looking for - yes.
This 'may' work for you:  ren file1.txt *.%date%.*

Otherwise, a small script may be in order:

===========
for /f "tokens=1-3 delims=/" %%a in ('date/t') do (
set newfile=%%a%%b%%c
)
ren file1.txt file1.%newfile%.txt
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 9771066
Now I further understand (man what was I smokin' yesterday?!)

To append both the date AND time to your file, try this one:

To pull just the hour and minute, proceed as follows:
::====================
for /f "tokens=1-3 delims=/" %%a in ('date/t') do (
set strDate=%%a%%b%%c

REM  Note the space after delims=: in the line below
for /f "tokens=1-2 delims=: " %%i in ('time/t') do (
set newfile=%strDate%%%i%%j
)
ren file1.txt file1.%newfile%.txt
::====================

Otherwise, if you're looking for seconds as well, create a mini-batch file like this:
===============
echo.|time|find "current" > tresults.txt
===============

then replace the "time" section above with:
[....]
for /f "tokens=5-8 delims=:. " %%w in ('ttest.cmd') do (
set newfile=%strDate%%%w%%x%%y%%z
)
[------]

Good luck!
~sirbounty
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Accepted Solution

by:
brianadkins earned 125 total points
ID: 9781193

One more way to skin the cat...

set OLDNAME=%1
set HH=%time:~0,2%
set MM=%time:~3,2%
set SS=%time:~6,2%
set MM=%date:~4,2%
set DD=%date:~7,2%
set YYYY=%date:~10,4%
set TIMESTAMP=%MM%%DD%%YYYY%%HH%%MM%%SS%

for /f "delims=." %%a in ("%OLDNAME%") do set NEWNAME=%%a.%TIMESTAMP%.%%b

ren %OLDNAME% %NEWNAME%


-Brian
0
 

Author Comment

by:mtgcpc
ID: 9783980
Thanks to both of you for responding.
0
 

Expert Comment

by:mcubitt
ID: 9796071
Brianadkins answer only works for a system with an American date format, so be careful!
0
 
LVL 5

Expert Comment

by:brianadkins
ID: 9796096


What other formats does %date% come in (i.e. other languages) ?

You may need to swap variables around if the year is listed first (but that would apply to all solutions above, nit just mine)

-Brian
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now