Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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...

Just delete the /F switch from your For statement, i.e.
For %%I in (c:\txt\*.txt) DO psexec %%I -c c:\reg.bat

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?

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?

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

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.

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.

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

![]() |
Help needed!! System rest...
|
Cableing Question?
|

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