Computing.Net > Forums > Windows XP > Reading files (XP Dos)

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.

Reading files (XP Dos)

Reply to Message Icon

Name: seralma
Date: October 25, 2005 at 00:01:11 Pacific
OS: Windows XP
CPU/Ram: Pentium 4/1 GB
Comment:

Hello,
I have the next problem that i can't resolve:
I need to read a file in a batch file (.bat)execution. For each line of that file I need to execute a command. (Can anybody help me??
Regards Sergio.

fisico



Sponsored Link
Ads by Google

Response Number 1
Name: jubalsams
Date: October 25, 2005 at 00:21:21 Pacific
Reply:

One can invoke another batch file with the CALL command. Or to just go to that other batch, just use it's name as a line.

Best


0

Response Number 2
Name: seralma
Date: October 25, 2005 at 01:15:04 Pacific
Reply:

Hi!!
Sorry by i can not understand you.

I am going to explain better my problem:

1) I have a batch file call 'init.bat' and i have other text file call 'del.txt'.
2) In 'del.txt' i store the file's name that i want to delete:
For example 'del.txt' could store:

file1.txt
file2.txt
file3.txt

3) I execute 'init.bat' and i want to read 'del.txt', after read each row i want to execute the command : delete <file>

4) then my execution should be:

- execute 'init.bat'
- for each row in del.txt execute
delete <each row>
end for

My questions are:
who can i read each line of my del.txt??
who can i store each line of my del.txt and then execute other command with that value??

Kind Regards
Sergio

fisico


0

Response Number 3
Name: IVO
Date: October 25, 2005 at 02:38:12 Pacific
Reply:

About your first question

How (I suppose who is a typo) can I read each line of my del.txt (and execute a del command)?

the answer is

For /f "tokens=* delims=" %%a in (del.txt) Do Del %%a

About your other question that is not clear to me, please explain better what you mean.


0

Response Number 4
Name: seralma
Date: October 25, 2005 at 08:40:07 Pacific
Reply:

Hello again!!

Your solution was fantastic for me. Thank you very much. (Forget my second question!!!)

But know i have other different problem:

I want to execute more than one command for each file's row.

In your answer (thank you again)

For /f "tokens=* delims=" %%a in (del.txt) Do Del %%a

I can only execute one command (del)

Is it posible to call a method with each row as a parameter and then execute differents commands ???

Example:

For /f "tokens=* delims=" %%a in (del.txt) CALL a method XXX

Where XXX is the method i want to use the value of each row)
command 1
command 2
...
command n

If i can not call a method, is it posible to execute more than one command???

Kind Regards.


fisico


0

Response Number 5
Name: IVO
Date: October 25, 2005 at 09:44:03 Pacific
Reply:

Yes, it is possible and you have two choices

First - rewrite the For to execute a "block sequence", i.e.

For /f "tokens=* delims=" %%a in (del.txt) Do (
Command1 %%a
.......
CommandN %%a)

where %%a is each row of your text file. A block sequence is a list of commands embedded between (...) each command holding one line..

Second - use an internal subroutine (much like a "method"), i.e.

For /f "tokens=* delims=" %%a in (del.txt) Do Call :Method %%a
.......
......-

:Method
Command1 %*
.......
.......
CommandN %*
GoTo :EOF

where :Method (with the leading :!) is the internal subroutine (Call on the same line holding For), %* is the row it refers (%%a in the For tail) and :EOF is the standard return point to not be declared as it is built in NT batch interpreter.

I hope I have explained in a clean way, if you need more help post again or mail me.


0

Related Posts

See More



Response Number 6
Name: vishal
Date: November 9, 2005 at 12:37:20 Pacific
Reply:

i have a question regarding this...i'm using a similar concept to make another script. But all the method calling etc is that done in the txt file or in the .bat file?



0

Response Number 7
Name: vishal
Date: November 9, 2005 at 12:42:55 Pacific
Reply:

my example is like

cd\Documents and Settings\%user\Application Data\Microsoft\Outlook\
xcopy *.* x:\%user\outlook /e

where %user comes from a list of users residing in user.txt file. so i need to read one user after the other..sort of in a while loop.

thanks.
Vishal


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 Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Reading files (XP Dos)

lg cd-rw in XP not reading files www.computing.net/answers/windows-xp/lg-cdrw-in-xp-not-reading-files/90570.html

reading file in DOS www.computing.net/answers/windows-xp/reading-file-in-dos/156143.html

Batch Files In 'XP DOS' www.computing.net/answers/windows-xp/batch-files-in-xp-dos/97697.html