Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch w/ wildcard using external data from text file  (Read 4188 times)

0 Members and 1 Guest are viewing this topic.

Relig

    Topic Starter


    Newbie

    Batch w/ wildcard using external data from text file
    « on: September 04, 2009, 03:45:21 PM »
    I'm trying to figure out a means to copy a single file from one location on to multiple workstations, but because the workstation names might change I want to put the names in a text file for the batch to take to plunk into the command.

    Something like

    :start
    get computername starting with line 1 from text file
    :process
    xcopy c:\filename.txt \\%computername%\folder
    get next computername from text file
    if last computername goto end
    goto process
    :end

    (robocopy might work better for this instead of xcopy)

    In the text file will have one column like:

    abc
    abb
    acc
    etc...

    Any sort of pointers would help greatly.  :)

    Salmon Trout

    • Guest
    Re: Batch w/ wildcard using external data from text file
    « Reply #1 on: September 04, 2009, 04:41:26 PM »
    Something along these lines perhaps?

    Code: [Select]
    for /f "delims==" %%A in (file.txt) do (
         xcopy c:\filename.txt \\%%A\folder
         )

    This FOR loop reads each line in turn from a text file called file.txt and substitutes that line for the computername in the xcopy command which is then executed

    Relig

      Topic Starter


      Newbie

      Re: Batch w/ wildcard using external data from text file
      « Reply #2 on: September 04, 2009, 04:59:17 PM »
      That seems to work. Thanks!  :D

      I tested this for another task, to rename a folder on muliple workstations and did it for one and worked like a charm. I'll do the file copy next once I get this task done...

      Now I just need to figure out 'upon error' goto next computer in case the pc is down and somehow report the missing computer.

      wbrost



        Intermediate
      • Thanked: 11
        Re: Batch w/ wildcard using external data from text file
        « Reply #3 on: September 08, 2009, 06:47:37 AM »
        Now I just need to figure out 'upon error' goto next computer in case the pc is down and somehow report the missing computer.

        what you could try and do is ping each computer and use the errorlevel to tell if the system is on or not. if the system is off then echo the computer name into a text file on the host (the system the batch is running on).