# Batch file for list



## irontechman (Sep 12, 2008)

I'm not brillient at scripting and have a list of computer names in a text file computer.txt with contents

computer1
computer2
computer3
etc

trying to run a batch file script

For %%w IN (computer.txt) Do Command dir \\%%w\c$\windows\inventory >>.txt

and of course this does not work... any ideas where I am going wrong?


----------



## Squashman (Apr 4, 2003)

I have never tried using a batch file with UNC paths and I don't think that it will work with the DIR command. I don't have any way to test it at work, but I can when I get home.

For /F %%w IN (computer.txt) Do dir \\%%w\c$\windows\inventory >> somefile.txt

You might want to look at using pstools.


----------



## TheOutcaste (Aug 8, 2007)

Welcome to TSG!


irontechman said:


> I'm not brillient at scripting and have a list of computer names in a text file computer.txt with contents
> 
> computer1
> computer2
> ...


DIR will work with UNC paths, at least from WinME on. 
It doesn't work in Win95/98/98SE, you have to map a drive to the path, then you can run dir on the mapped drive.

But Squashman has it right, you have to use the */F* switch so it will read the _content_ of *computer.txt*, not just the file name. The for loop without that switch is intended to have multiple files in the list and do the command on each file:
For %%w in (file1.txt file 2.txt file3.txt) do copy %%w c:\backup

Will copy the three files listed to c:\backup, it won't read the contents.

Also, probably a typo in the post, but you have *>>.txt* -- you need a file name, not just the extension.

HTH

Jerry


----------

