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

batch file to rename files by date.

Reply to Message Icon

Original Message
Name: Skidog
Date: January 19, 2001 at 10:07:57 Pacific
Subject: batch file to rename files by date.
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


Report Offensive Message For Removal


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

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.


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal

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

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.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: batch file to rename files by date.

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge