Computing.Net > Forums > Programming > Batch file to rename 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.

Batch file to rename file

Reply to Message Icon

Name: Brian3864
Date: February 8, 2006 at 14:33:00 Pacific
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



Sponsored Link
Ads by Google

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

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.


0

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

Hi Brian,

I'm working on it.


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

M2


0

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

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


0

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

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


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 Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file to rename file

XP batch script to rename files www.computing.net/answers/programming/xp-batch-script-to-rename-files/14608.html

Batch Script To Rename File www.computing.net/answers/programming/batch-script-to-rename-file/16798.html

Batch file copy and Rename www.computing.net/answers/programming/batch-file-copy-and-rename/18689.html