Computing.Net > Forums > Programming > Batch file to rename file

Batch file to rename file

Reply to Message Icon

Original Message
Name: Brian3864
Date: February 8, 2006 at 14:33:00 Pacific
Subject: Batch file to rename file
OS: Windows 2000 advanced ser
CPU/Ram: PIII/1GB
Comment:

I have a program that creates daily log files that are a lot larger than I would like them to be. I would like to have this so there would be 3 or 4 log files daily. The logs are named logMMDD.txt. I would like to create a batch file to simply rename the log file so that the program creates a new log file and run this 2 or 3 times daily. Can someone help me out as to how to go about grabing the latest file name and renaming it?

Thanks,
Brian


Report Offensive Message For Removal


Response Number 1
Name: shahramsh
Date: February 9, 2006 at 13:26:45 Pacific
Reply: (edit)

Why don't you try to put a unique sign on the new files, so you can find the file without the sign (the last file) and do whatever you want with it.


Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: February 9, 2006 at 13:39:39 Pacific
Reply: (edit)

Hi Brian,

I'm working on it.


If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: February 9, 2006 at 14:46:51 Pacific
Reply: (edit)

Try this.

I know it's messy.

::== renLOGS.bat
@ echo off

if not exist logs\*.txt echo nothing to do && goto :eof
set gotEXT=N
dir /b /o-d logs\log????.* | find /i /v "txt">logLIST
for /f %%N in (logLIST) do call :sub1 %%N
dir /b logs\log????.* | find /i "txt">logTXT
set /p currLOG=<logTXT
set currNAME=%currLOG:~0,7%
ren logs\%currNAME%.txt %currNAME%.%nextEXT%
goto :eof

:sub1

if %gotEXT%==Y goto :doneHERE
set last=%1
set lastEXT=%~x1
set lastEXT2=%lastEXT:~1,3%
set /a nextEXT=%lastEXT2%+1
set gotEXT=Y
:doneHERE
goto :eof
:: DONE


If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 4
Name: thegrmreaper
Date: March 9, 2006 at 15:33:15 Pacific
Reply: (edit)

how about appending them to one log file?

this is a log of the contents of c:\

@echo off
cd \
echo %date% >> log.txt && echo dir >> log.txt || echo error
:eof


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 file

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 Today.
Discuss in The Lounge