Computing.Net > Forums > Windows NT > Batch: data from several *txt files

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: data from several *txt files

Reply to Message Icon

Name: Xypriz
Date: December 5, 2003 at 04:37:29 Pacific
OS: Win XP
CPU/Ram: P4-1600-256MB
Comment:

All,

I want to make a batch file which looks into a certain directory for *.txt files. In these *.txt files a computer hostname is mentioned, which should be read as a variable for a command.

So far I have got this:

FOR /F %%i IN (c:\txt\test.txt) DO psexec %%i -c c:\reg.bat

This works, but only for the "test.txt" file. I want to make it work for ALL txt files in the specified directory. When I replace (c:\txt\test.txt) with (c:\txt\*.txt) it doesn't work. It says that it cannot find "*.txt" (thinking *.txt is the file name).

I tried utilities like FORTUNE and FORALL but I don't really understand how to get it working in this case.

Can anyone help me?

Thnx in advance...




Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: December 5, 2003 at 08:25:34 Pacific
Reply:

Just delete the /F switch from your For statement, i.e.

For %%I in (c:\txt\*.txt) DO psexec %%I -c c:\reg.bat



0

Response Number 2
Name: x86
Date: December 5, 2003 at 23:28:59 Pacific
Reply:

http://www.ss64.com/ntsyntax/index.html


0

Response Number 3
Name: Xypriz
Date: December 8, 2003 at 02:29:55 Pacific
Reply:

Hmzzz...

the batch file does pick up each txt file now but it seems that the "IN"-command doesn't work anymore as it uses "c:\txt\filename.txt" as variable for %I and not the contents of the txt files.

Do I forget something here?


0

Response Number 4
Name: IVO
Date: December 8, 2003 at 02:52:51 Pacific
Reply:

The For command loops through a list of files (C:\txt\*.txt) assigning each one to the variable specified to be used as operand in a sub-command (the Do psexec) statement, but it does not deal with *the content* of files, the IN does not mean what you believe, it refers to the object(s) specified. To parse the objects For /F shoud then be used, but then the structure of the text must be defined.
From your post I understood that piece of processing was performed by psexec, so what is the structure of the txt files and which operands does psexec expect?


0

Response Number 5
Name: Xypriz
Date: December 8, 2003 at 03:19:29 Pacific
Reply:

Hi,

well the txt files contains nothing more than a computer hostname like: \\TESTCOMPUTER01.

This hostname should be picked up by psexec. The command for psexec is then:
psexec \\TESTCOMPUTER01 -c c:\reg.bat

This works only when I use FOR with /F, but then only for a single txt file.

What I would like to achieve is the following:
1. People log on to their computer.
2. A login script is processed but for the execution of this script a file called "kixforms.dll" is needed. When people does not have the rights to install this dll, the login script writes a txt file to a server share. In this txt file is the workstation name mentioned.
3. A small batch, which is scheduled to run once a hour, picks up the txt file and starts pushing the dll to the client and install it remotely with sufficient rights.
4. The txt file is moved to a directory called "installed" so it won't be pick upped at the next scheduled job.

I thought about the option to let clients write in 1 single txt (append), but I don't know how to remove the lines of the installed clients via a batch command. Those lines should be written in a installed.txt then as well so I know which clients are facing problems and which not. This looks difficult to me to accomplish so that's why I chose for the other option (every workstation their own txt).

Can you help me solve this issue?



0

Related Posts

See More



Response Number 6
Name: IVO
Date: December 8, 2003 at 12:44:47 Pacific
Reply:

Well, now I understand your problem and can suggest you the following statement

For /F %%A in ('Dir /B C:\txt\*.txt') Do (
For /F %%B in (C:\txt\%%A) Do Echo psexec %%B -c C:\reg.bat)

I tested it quite carefully and it worked fine picking up the workstation name contained in .txt files for the psexec command.

If anything goes wrong, post again.


0

Response Number 7
Name: IVO
Date: December 8, 2003 at 12:53:29 Pacific
Reply:

Obviously omit the Echo in front of psexec; I typed that for testing purpose only.
Beware: new line after the first "Do (" then a single line ending with ")".
The statement is made by two lines as total.


0

Response Number 8
Name: Xypriz
Date: December 9, 2003 at 02:03:57 Pacific
Reply:

You're the man!

That batch does it!

When I run into troubles I will post another reply but so far this seems to work great.

Thnx!!


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 NT Forum Home


Sponsored links

Ads by Google


Results for: Batch: data from several *txt files

Reg entries to txt file www.computing.net/answers/windows-nt/reg-entries-to-txt-file/14319.html

Getting Data from NT Laptop in Dos ? www.computing.net/answers/windows-nt/getting-data-from-nt-laptop-in-dos-/18297.html

FAT32X Partition www.computing.net/answers/windows-nt/fat32x-partition/4816.html