Computing.Net > Forums > Disk Operating System > Renaming Files in DOS Batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Renaming Files in DOS Batch file

Reply to Message Icon

Name: MARK DAVIES
Date: January 22, 2002 at 02:31:15 Pacific
Comment:

I need to write a DOS Batch file that renames a file to it`s original name plus todays date.

e.g. TEST.TXT becomes TEST220102.TXT

I need the batch file to dynamically look up todays date and append the correct date each time the file is run. Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: the Reverend
Date: January 22, 2002 at 11:06:29 Pacific
Reply:

That sounds pretty interesting, man... I wouldn't mind checking that out myself on my DOS box at home. I'm at work until 8pm PST right now, and we only run NT here, but when I get home, I'll check it out and see what I can do.

You should submit here if you find it, because it sounds pretty cool too.

DOS rules, by the way.


0

Response Number 2
Name: Secret_Doom
Date: January 22, 2002 at 14:19:13 Pacific
Reply:

The following script is deactivated.
Run it and see if it prints out on the screen the correct operation. If it does so, activate the script by taking out the "EcHo" from the line indicated.

=== Script begin (omit this line) ===

@echo off
echo @PROMPT SET DATE=$D$_>%temp%.\$$tmp.bat
%comspec% /c%temp%.\$$tmp.bat>%temp%.\$$tmp2.bat
echo e111';'> %temp%.\$$tmp.bat
echo e114';'>> %temp%.\$$tmp.bat
echo e117';'>> %temp%.\$$tmp.bat
echo w>> %temp%.\$$tmp.bat
echo q>> %temp%.\$$tmp.bat
debug.exe %temp%.\$$tmp2.bat<%temp%.\$$tmp.bat>nul
call %temp%.\$$tmp2.bat
echo SET DATE=%%2%%3%%4> %temp%.\$$tmp.bat
call %temp%.\$$tmp.bat;%date%

::Take out the "EcHo" to activate script
EcHo REN TEST.TXT TEST%DATE%.TXT

if exist %temp%.\$$tmp.bat del %temp%.\$$tmp.bat
if exist %temp%.\$$tmp2.bat del %temp%.\$$tmp2.bat
SET DATE=

=== Script end (omit this line) ===

! WATCH OUT FOR LINE WRAPPING !

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br

PS: Batch programmers: I know this script could be greatly reduced by using FOR, but I didn't use it to avoid more line wrapping


0

Response Number 3
Name: Secret_Doom
Date: January 22, 2002 at 14:24:39 Pacific
Reply:

BTW: The following lines from script from my last post have wrapped:

echo @PROMPT ... $$tmp.bat

%comspec% ... $$tmp2.bat

debug.exe ... >nul

echo SET DATE= ... > %temp%.\$$tmp.bat

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 4
Name: Secret_Doom
Date: January 22, 2002 at 14:31:28 Pacific
Reply:

Hey... now I refreshed the page and my first reply was cutted, besides the line that has "debug.exe" on its begin have being modifyed. I don't know what's happening to this f---ing forum, so I uploaded that script:

www.batch.hpg.com.br/dateren.txt

Just download it and rename its extention to .bat

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 5
Name: Laurence
Date: January 25, 2002 at 13:48:04 Pacific
Reply:

How about the ranaming part?
Figured that one out yet ;)?


0

Related Posts

See More



Response Number 6
Name: Sat
Date: March 15, 2002 at 07:57:30 Pacific
Reply:

Hi,
I tried this
www.batch.hpg.com.br/dateren.txt
and it did not work.Can you help me out ..

Sat


0

Response Number 7
Name: andyp
Date: April 18, 2002 at 09:50:59 Pacific
Reply:

Look for a utility called FDATE.exe. This makes life much easier. It was written by Stephen Ferg in 1997 and works on all Windows platforms.

I downloaded it from:

http://sac-ftp.externet.hu/utiltask3.html

aap


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Renaming Files in DOS Batch file

File Size in DOS Batch file www.computing.net/answers/dos/file-size-in-dos-batch-file/3105.html

What is >nul mean do in a batch file www.computing.net/answers/dos/what-is-nul-mean-do-in-a-batch-file/197.html

archive in dos batch file www.computing.net/answers/dos/archive-in-dos-batch-file/12924.html