Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Greetings,
I would like to be able to read the header record from a file that is numerically named (i.e. 844205) and rename that file accordingly with the date appending.
For example, I have report number 837854 and the first record contains ID=tree. If id=tree then rename it 'tree-110108.txt'. The file name is always different. Thanks.
Rob

Getting the date in the above format is quite a task.
If it is ok to rename in whatever format your %date% is, then the below script may work:
May be slow though.
The batch file has to reside somewhere else, not in the current directory, because then it would try to rename itself :-(
@echo off
setlocal enabledelayedexpansion
for %%a in (*.*) do (
set iLine=0
for /f "tokens=2 delims==" %%i in (%%a) do (
set /a iLine=!iLine! + 1
if !iLine!==1 (
set id=%%i
ren %%a !id!-%date%.txt
)
)
)
endlocal--
Holla.

ID=tree
Is that all that's in the first record?
=====================================
If at first you don't succeed, you're about average.M2

Holla,
Thank you for your reply. The code that you provided is returning: "The syntax of the command is incorrect" x2
Rob

You need to post the first line.
We'll deal with the renaming later.
=====================================
If at first you don't succeed, you're about average.M2

Sorry for not specifying earlier, but if ID=tree then tree will not be part of the naming convention, it is just a way to determine the naming convention. So if ID=tree then rename the file
"issue-112008.txt".Rob

I see the line in #7 but you lost me with the naming convention in #6.
=====================================
If at first you don't succeed, you're about average.M2

Sorry about that.
Let's just say if the first row is:
$$ADD ID=TREE BID='754647-TEST'I then want to rename the file
"issue-112008.txt" (issue is derived from ID=tree)Rob

"(issue is derived from ID=tree)"
how?
=====================================
If at first you don't succeed, you're about average.M2

Sorry, I am having trouble explaining this.
If ID=tree then I want the beginning of the file to start with issue. Technically it is not derived, it's just how I want the the file to be named.
Each day, I will have 4 files, each with different ID's. All 4 will need to be renamed (it does not matter for now how we choose to rename them as long as they are different). The next day the process repeats with 4 new files (the only difference is the new date appended to the end). Does that make sense?
Rob

So the name prefix has nothing to do with the file content?
=====================================
If at first you don't succeed, you're about average.M2

I'm glad it only took 12 replies to clear that up.
This uses RANDOM to rename. Should not be a problem unless you have tons of files.
============================================
@echo off
setLocal EnableDelayedExpansioncall :ymd8
for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
echo ren %%a !random!-!year!!month!!dat!%%~Xa
)
goto :eof:ymd8
::== YMD8.bat
@echo off > d.d
>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Qdebug < d.d > nul
del d.ddat
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set dat=0%%a
for %%a in ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set dat=%%a
::echo Date %dat%day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
::echo Day %day%month
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set month=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set month=%%a
::echo Month %month%year
if errorlevel 215 set Year=2007
if errorlevel 216 set Year=2008
if errorlevel 217 set Year=2009
if errorlevel 218 set Year=2010
::echo Year %Year%del day.com
del month.com
del year.com
del dat.com
::== DONE
=====================================
If at first you don't succeed, you're about average.M2

![]() |
Creating folders automati...
|
Automaticly organize fold...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |