+ Post New Thread
Results 1 to 3 of 3
Scripts Thread, For Next Loop in Batch File in Coding and Web Development; Hi everyone Ive written a small batch file that connects to remote computers, lists the folders in Docments and Settings ...
  1. #1

    Join Date
    Feb 2008
    Location
    Gloucester
    Posts
    36
    Thank Post
    6
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    For Next Loop in Batch File

    Hi everyone

    Ive written a small batch file that connects to remote computers, lists the folders in Docments and Settings folder and outputs the results to a text file. The problem is that only results from the last remote computer in the file is output to the text file. I want to have all the computers reults written to the text file. Batch file is as follows:-

    for /f %%i in (c:\computers.txt) do dir /ad "\\%%i\c$\Documents and Settings" > results.txt

    I think i need a for next loop

    Any help and guidance would be appreciated

    Regards
    Barry Stone

  2. #2

    Join Date
    Apr 2007
    Location
    Birmingham
    Posts
    142
    Thank Post
    6
    Thanked 45 Times in 39 Posts
    Rep Power
    22
    Not sure if its exactly what you wanted, but using >> will append to the file.

    e.g for /f %%i in (c:\computers.txt) do dir /ad "\\%%i\c$\Documents and Settings" >> results.txt

    Alternatively if you want a file for each computer, perhaps this?

    for /f %%i in (c:\computers.txt) do dir /ad "\\%%i\c$\Documents and Settings" > "results %%i.txt"
    Last edited by andy_b; 17th March 2011 at 01:10 PM.

  3. Thanks to andy_b from:

    barrystone (17th March 2011)

  4. #3

    Join Date
    Feb 2008
    Location
    Gloucester
    Posts
    36
    Thank Post
    6
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks

    Thats fixed it

    Now working a treat

    Regards

    Barry Stone

SHARE:
+ Post New Thread

Similar Threads

  1. Batch File (select random file) help
    By fil_b in forum Windows Server 2000/2003
    Replies: 5
    Last Post: 5th November 2009, 04:13 AM
  2. batch file comman
    By jussy65 in forum Scripts
    Replies: 3
    Last Post: 13th August 2008, 07:10 AM
  3. Pass in batch file
    By meastaugh1 in forum Windows
    Replies: 2
    Last Post: 17th January 2008, 08:02 PM
  4. batch file help
    By beeswax in forum Scripts
    Replies: 9
    Last Post: 3rd March 2006, 07:48 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •