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
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?
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
Summary: It just came to mind while looking at M2's code, that you dont need to write the Dir to a file first. Here's sum improved code: ::----CODE---- md c:\lih\tmp for /f "tokens=*" %%i in ('dir/b "c:\lih\po...
Summary: This topic seems beaten into the ground, however, any help would be appreciated. I'm trying to piece together a script that'll rename a season of a show. I've been trying to learn myself. But, am sti...
Summary: 1) In the script to RENAME files change this line: ren %%2 !level2!%%2 to: ren %%2 !level2!-%%2 In the script to COPY the files change this line: copy %%2 !level1a!\!level2!\!level2!%%2 > nul to: co...