Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
After finding a chacter string in a given file, I want to rename the file using a portion of that character string.
1. I am using a .bat program
2. File locker.rpt is in my working directory
3. running a .bat file and using command:
find/I/N "locker number" locker.rpt4. the screen displays (for example):
--------- locker.rpt
[##]-A locker number:T27b198c5578b5. I am to trying to use the .bat file to rename locker.rpt
6. The renamed file should be:
T27b198c5578b.rpt7. I understand there may be a limit to the # of charaters, but so long as the file name starts with the "T", that's OK
8. The first character of the new file name ("T" in this example) is always the 27th character displayed on the line returned by the Find command and beginning with "[".
Any suggestions would be greatly appreciated
thanks
dave

Dave wrote:
> 8. The first character of the new file
> name ("T" in this example) is always the
> 27th character displayed on the line
> returned by the Find command and beginning
> with "[".You are aware that on the line you posted the "T" appears as the 22th character, right? I'll assume the right information is 27th.
I'll also assume you just mentioned steps 1 to 3 to state what you've already managed to do, but that you don't actually need such steps to be followed. I will follow a slightly different path.
The following batch file will do it:
@echo off
FIND /i "A locker number" < locker.rpt > %temp%.\t1.tmp
echo e113'SET %%1='> %temp%.\t2.bat
for %%? in (f100L13''20 w q) do echo %%?>> %temp%.\t2.bat
DEBUG %temp%.\t1.tmp < %temp%.\t2.bat > nul
FIND "SET %%1=" < %temp%.\t1.tmp > %temp%.\t2.bat
call %temp%.\t2.bat LOCKNUM
for %%? in (t1.tmp t2.bat) do del %temp%.\%%?
ren locker.rpt %locknum%.rpt
set locknum=-- Leonardo Pigntaro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br________________________________________________________________

Hello,
Almost there. You were correct about the character count being off. The resulting file name is missing the first 4 characters.
actual result is 198c5578b.rpt
desired output is T27b198c5578b.rptI tried to revise the code, but I was unable to do so.
thanks
dave

Then, it would be from the 23th character and on, right? Here's the revised code:
@echo off
FIND /i "A locker number" < locker.rpt > %temp%.\t1.tmp
echo e10F'SET %%1='> %temp%.\t2.bat
for %%? in (f100LF''20 w q) do echo %%?>> %temp%.\t2.bat
DEBUG %temp%.\t1.tmp < %temp%.\t2.bat > nul
FIND "SET %%1=" < %temp%.\t1.tmp > %temp%.\t2.bat
call %temp%.\t2.bat LOCKNUM
for %%? in (t1.tmp t2.bat) do del %temp%.\%%?
ren locker.rpt %locknum%.rpt
set locknum=-- Leonardo Pigntaro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br________________________________________________________________

Hello,
yes it works......and thank you very much.
the only changes were:
e113------>e10f
e100L13---> F100LFIf you find time...please explain. I do not yet understand why this worked.
Does it have something to do with Hex #'s (113_H = 275_d, 10F_H = 271_d)
Again,
my thanks for all the help
dave

The batch script used a DEBUG script, with the following text:
e10F'SET %1='
f100LF''20
w
qWhen using DEBUG to debug a file, its data is loaded on offset 100h. The first line from the debug script writes the string "SET %1=" to offset 10Fh, which corresponds to the 16th character from the file. The second line Fills with spaces (space = ASCII 20h) starting at offset 100h (beginning of file) and with Length of Fh characters (15 spaces). Third line Writes the file (like a "save" command) and fourth line Quits.
So, let's suppose the line on the t1.tmp, right before the DEBUG script takes action, is:
A locker number to me:T1234
0123456789ABCDEF0123456789ABCDEF (hex)
123456789012345678901234567890 (dec)Those numbers are the offsets. The "0" on the hex offset is 100h, and the "1" on the dec offset is the 1st character.
-e10F'SET %1='
A locker numberSET %1=T1234
0123456789ABCDEF0123456789ABCDEF (hex)
123456789012345678901234567890 (dec)-f100LF''20
SET %1=T1234
0123456789ABCDEF0123456789ABCDEF (hex)
123456789012345678901234567890 (dec)Afterwards, we extract from t1.tmp only the line with the string "SET %1=" (with FIND cmd) since there could me additional lines on the file, and we run the resulting file, which has a .bat extention (t2.bat).
Got it?
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

Hello,
It took some time, but yes...I understand.
I found the following sites helpful in learning the DOS command set:
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/winxppro/proddocs/ntcmds.asp
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/winxppro/proddocs/dos_cmds.asp
thanks again
dave

> It took some time, but yes...I understand
That's normal, it is indeed complex hehe...
> I found the following sites helpful in
> learning the DOS command setJust keep in mind that such help information is about Windows XP, where the command SET has many more capabilities than on Win9x/DOS. On NT systems, all this offset thing with debug is totally unecessary.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

Hi all,
Can any one help completing this batch file. am taking backups of the access database every hr and i would like to keep each backup for all day long and for that i need to rename the file name with filename+currenttime.can any one help me out with this..
thanxs
V

![]() |
![]() |
![]() |

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