Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Renaming a file to today's date  (Read 4814 times)

0 Members and 1 Guest are viewing this topic.

jbs

  • Guest
Renaming a file to today's date
« on: August 26, 2004, 01:17:56 PM »
I am trying to rename a file to include the current date.  So I want to rename the file myfile.txt to myfile08262004.txt.  I am writing this program that will create this file every month and put it out in a directory.  Once it is there I am using DOS to rename the file to the current date and then FTP to a server. I can't find a way to rename my file to the current system date..can anyone help??

Thanks in advance!

yeah_right

  • Guest
Re: Renaming a file to today's date
« Reply #1 on: August 26, 2004, 01:56:03 PM »
check the thread "whos an expert with dos?" ... same issue
« Last Edit: August 26, 2004, 01:56:35 PM by yeah_right »

Willz

  • Guest
Re: Renaming a file to today's date
« Reply #2 on: November 18, 2004, 07:14:51 PM »
Have a look at this
rem *** Moves JFMOVE to E:\JFBACKUP\Raw_Data and renames it as the System Date and Time ***
----------------------------------------------------------------------
Move E:\JFBACKUP\JFMOVE "E:\JFBACKUP\Raw_Data\%date:~4,2%%date:~7,2%%date:~-2,2%%time:~0,2%%time:~3,2%"
------------------------------------------------------------------------
Have study of this lines I used in my Batch. That's the working format for me.

Cheers!
Willz

franksimari

  • Guest
Re: Renaming a file to today's date
« Reply #3 on: November 19, 2004, 12:55:03 PM »
use the copy command (many parts to this powerful command)

copy oldfile +,,


thats it!  you may be prompted to overwrite the oldfile.
say yes.  if your anxious about it copy it to a different directory
and try it there

HotShot

  • Guest
Re: Renaming a file to today's date
« Reply #4 on: November 24, 2004, 05:49:24 AM »
Well I live the UK and all my system dates are in UK format, so for those of you (like me) who need it simple:

Code: [Select]
MOVE "c:\myfile.txt" "c:\myfile_%date:~0,2%-%date:~3,2%-%date:~6,4%_%time:~0,2%-%time:~3,2%-%time:~6,2%-%time:~9,2%.txt"

The line above will RENAME "c:\myfile.txt" to "myfile_24-11-2004_12-48-04-39.txt"

Hope this helps someone else.

PS -  can't find the old thread, mentioned above.