Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

RENAME or REN with a date and time stamp

Posted on 2003-11-17
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

Question by:mtgcpc
LVL 67

Expert Comment

ID: 9767716
How about copy filename +/b
This will update the time stamp to the current
LVL 67

Expert Comment

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
LVL 67

Expert Comment

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!
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Accepted Solution

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%

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



Author Comment

ID: 9783980
Thanks to both of you for responding.

Expert Comment

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

Expert Comment

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)


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find and Copy Specific Files from a Subfolder Tree 6 62
Batch File Bulk File Rename 3 61
quick dos batch to update files. 3 63
WMIC Command LIne 5 43
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

792 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