Computing.Net > Forums > Disk Operating System > DOS Find char, Ren file, bat 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.

DOS Find char, Ren file, bat file

Reply to Message Icon

Name: dave
Date: July 17, 2003 at 16:35:17 Pacific
OS: win98
CPU/Ram: 128
Comment:

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.rpt

4. the screen displays (for example):

--------- locker.rpt
[##]-A locker number:T27b198c5578b

5. I am to trying to use the .bat file to rename locker.rpt

6. The renamed file should be:
T27b198c5578b.rpt

7. 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



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: July 17, 2003 at 20:14:18 Pacific
Reply:

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

________________________________________________________________


0

Response Number 2
Name: dave
Date: July 18, 2003 at 05:05:18 Pacific
Reply:

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.rpt

I tried to revise the code, but I was unable to do so.

thanks
dave



0

Response Number 3
Name: Secret_Doom
Date: July 18, 2003 at 12:07:25 Pacific
Reply:

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

________________________________________________________________


0

Response Number 4
Name: dave epee
Date: July 18, 2003 at 12:48:12 Pacific
Reply:

Hello,

yes it works......and thank you very much.

the only changes were:

e113------>e10f
e100L13---> F100LF

If 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


0

Response Number 5
Name: Secret_Doom
Date: July 18, 2003 at 13:06:43 Pacific
Reply:

The batch script used a DEBUG script, with the following text:

e10F'SET %1='
f100LF''20
w
q

When 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


0

Related Posts

See More



Response Number 6
Name: dave epee
Date: July 19, 2003 at 08:00:27 Pacific
Reply:

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


0

Response Number 7
Name: Secret_Doom
Date: July 19, 2003 at 10:45:32 Pacific
Reply:

> 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 set

Just 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


0

Response Number 8
Name: V
Date: August 5, 2003 at 07:43:15 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: DOS Find char, Ren file, bat file

setting a dos variable from text file www.computing.net/answers/dos/setting-a-dos-variable-from-text-file/7785.html

I need to find mouse.com in DOS to repair corrupted file www.computing.net/answers/dos/i-need-to-find-mousecom-in-dos-to-repair-corrupted-file/5470.html

using part of output to ren file www.computing.net/answers/dos/using-part-of-output-to-ren-file/7812.html