Computing.Net > Forums > Disk Operating System > batch file to rename files by date.

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.

batch file to rename files by date.

Reply to Message Icon

Name: Skidog
Date: January 19, 2001 at 10:07:57 Pacific
Comment:

Help! I'm have been trying to figure a way to write a batch file that will automatically rename a specific file by the date and time.

example: skidog.txt ==> jan191230.txt



Sponsored Link
Ads by Google

Response Number 1
Name: World Library
Date: January 19, 2001 at 12:06:56 Pacific
Reply:

Hmmm.
The below will rename a file in dir\test
to todays date. Just change the path.


CLS
@ECHO OFF
IF NOT "%1"=="date" ECHO Program will rename ECHO a filewith todays date.
IF "%3"=="Mon" SET Day=Monday
IF "%3"=="Tue" SET Day=Tuesday
IF "%3"=="Wed" SET Day=Wednesday
IF "%3"=="Thu" SET Day=Thursday
IF "%3"=="Fri" SET Day=Friday
IF "%3"=="Sat" SET Day=Saturday
IF "%3"=="Sun" SET Day=Sunday
Set FullDate=%4
goto getdate
:start2
echo rename test\*.* %fulldate%.* > try.bat
call try
rem del try.bat
goto end
:getdate
ECHO.|DATE>t.bat
CALL t.bat
DEL t.bat
goto start2
:end
echo A file called %fulldate% has been ECHO created.


0

Response Number 2
Name: Schlep
Date: April 10, 2001 at 00:19:20 Pacific
Reply:

Easiest approach:

Requires the ability to use the DOS extensions (NT4 SP3 or SP4 onwards I think???)


rem Rename File

@echo off

rem Enable Extensions
verify other 2>nul
setlocal enableextensions
if errorlevel 1 goto ErrNoExtensions

rem Set current Date & Time variables. Change the following lines to get the correct info out. For more info, use the DOS command: help set
set SHORTDATE=%DATE:~10,4%%DATE:~7,2%%DATE:~4,2%
set SHORTTIME=%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

rem Rename file
ren %1 %SHORTDATE%_%SHORTTIME%.*

endlocal

goto end

:ErrNoExtensions
echo Extensions not enabled. Cannot continue.

:End


0

Response Number 3
Name: John Jones
Date: June 5, 2001 at 23:26:16 Pacific
Reply:

I am looking to make a similar script, but mine needs to capture the output of a small dos application i have created and rename the file to that output.
c:\test.exe file.txt
OUTPUT

I want file.txt to be renamed to OUTPUT, but i cant figure out how. Thanks in advance.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: batch file to rename files by date.

Deleting Files by Date?? www.computing.net/answers/dos/deleting-files-by-date/10697.html

Deleting Files by Date?? www.computing.net/answers/dos/deleting-files-by-date/10700.html

delete old files by date www.computing.net/answers/dos/delete-old-files-by-date/13057.html