Jump to content

Pulling information from text file


Recommended Posts

I am not sure what command to use to grab a computer name from a text file, run command, grab another computer, run command and repeat until EOF.

What I am wanting to do is run a script from my PC that goes out over our network to about ~150 PCs and cuts a folder from a specific users program group and then pastes it into the All Users program group. I am wanting to grab all the PC names from a text file, and that is the command I am not sure about.

Example:

Cut \\computer01\c$\Documents and Settings\user50\Start Menu\Programs\FoldertoCopy

Paste to \\computer01\c$\Documents and Settings\All Users\Start Menu\Programs\

But I don't want 300 lines of text for each computer. Can someone recommend the command I should use for grabbing the computer name from a text file where it will run each line until EOF?

Edited by BrandonW
Link to comment
Share on other sites

You create the text file yourself ?

Like :

Username1

Whatever

.....

???

Then use FileReadLine function.

Yeah ... we are in the middle of re-imaging ~200 computers and have come across the issue where only a specific logged on user can see the FoldertoCopy in the program files. That user is me and that is only because I am the one who ran the script to install it (which I am in the middle of trying to modify). It isn't too mission critical at the moment, which is why they are letting the scripting n00b figure it out.

I have kept track of the ~120 (Got a better count) machines I have deployed and put them in a text file. I am wanting the script to grab a computer name from the text file, insert it into a UNC path string and copy the specified folder to a different folder on that same machine. Then loop through the script again with the next computer name in the text file inserted into the UNC path.

I am looking at FileReadLine and thinking I might be able to get it to work with that. Going to see what I can do now. Thanks guys!

Edited by BrandonW
Link to comment
Share on other sites

Ok I have tried this about 50 different ways and just can't figure out due to my total lack of scripting knowledge.

$file = FileOpen("qsdeployed.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    $Path = "\c$\Documents and Settings\brandon\Start Menu\Programs\Quantitative Sentinel"
    If @error = -1 Then ExitLoop
    DirCopy($line & $Path, @ProgramsCommonDir, 0)
Wend

This was just my final attempt before getting too frustrated. I am not sure how to set a variable for the path (I tried $var, but wasn't sure what to put after the equal sign). Then I am not too sure how to combine the $line and $Path. In my text file, I have the computer as: \\Computername

I also started by doing the message box to make sure it was opening the txt file and it read out the computer name just as it is above.

For the moment I am just trying to copy it to my local PC where I am running the script.

Help :D

Edited by BrandonW
Link to comment
Share on other sites

$file = FileOpen("qsdeployed.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    ;$Path = "\c$\Documents and Settings\brandon\Start Menu\Programs\Quantitative Sentinel"
    If @error = -1 Then ExitLoop
    MsgBox (0, "", @DocumentsCommonDir & "\" & $line)
    ;DirCopy($line & $Path, @ProgramsCommonDir, 0)
Wend

Is this one step closer ?

From where to where will the copying take place ?

Link to comment
Share on other sites

$file = FileOpen("qsdeployed.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    ;$Path = "\c$\Documents and Settings\brandon\Start Menu\Programs\Quantitative Sentinel"
    If @error = -1 Then ExitLoop
    MsgBox (0, "", @DocumentsCommonDir & "\" & $line)
    ;DirCopy($line & $Path, @ProgramsCommonDir, 0)
Wend

Is this one step closer ?

From where to where will the copying take place ?

It is copying a folder on a remote PC to a different folder on that same PC. Basically moving a start menu program folder (named quantitative sentinel) to the All Users program folder. I'm thinking where it might not work is I am needing to run UNC paths. Example:

Copy the QS folder from: \\computer1\c$\Documents and Settings\user\Start Menu\Programs\QS

to: \\computer1\c$\Documents and Settings\All Users\Start Menu\Programs\QS

then grab the next computer name from the text file so it does:

Copy the QS folder from: \\computer2\c$\Documents and Settings\user\Start Menu\Programs\QS

to: \\computer2\c$\Documents and Settings\All Users\Start Menu\Programs\QS

The msgbox came up with: C:\Documents and Settings\All Users\Documents\\\computer1

I switched it to where the \\computer1 comes first. I guess to get my c$ I am going to have to type out the path in the script? No way of setting a variable like $line ?

Edited by BrandonW
Link to comment
Share on other sites

The username is always "user' ?! Check this out :

$file = FileOpen("qsdeployed.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    MsgBox (0, "", "\\" & $line & "\" & "c$Documents and Settings\user\Start Menu\Programs\QS")
Wend
Edited by Inverted
Link to comment
Share on other sites

The username is always "user' ?! Check this out :

$file = FileOpen("qsdeployed.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    MsgBox (0, "", "\\" & $line & "\" & "c$Documents and Settings\user\Start Menu\Programs\QS")
Wend
Yes, it will be copying from the same user folder everytime to All Users.

While 1
    $line = FileReadLine($file)
    $path = "c$\Documents and Settings\ept9514\Start Menu\Programs\Quantitative Sentinel"
    If @error = -1 Then ExitLoop
    MsgBox (0, "", $line & "\" & $path)
   ;DirCopy($line & $Path, @ProgramsCommonDir, 0)
Wend

I came up with that which appears to be the same. I like yours since I won't have to change my full text file to have all the \\

Gonna give it a go now. Thanks Inverted!

Link to comment
Share on other sites

Remember to check for 0 return (failure) after the DirCopy and show an error, so you know when/if it failed.

Indeed it is failing and I see why but have no clue how to fix it.

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$file = FileOpen("qsdeployed.txt", 0)

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    $path = "c$\Documents and Settings\user\Start Menu\Programs\Quantitative Sentinel"
    $path2 = "c$\Documents and Settings\All Users\Start Menu\Programs"
    If @error = -1 Then MsgBox (0, "", "Failed")
;   DirCopy($line & "\" & $path, $line & "\" & $path2, 0)
***  MsgBox (0, "", $line & "\" & $path, $line & "\" & $path2)
Wend

After the comma on the *** line, it is not picking of the $line. Just the $path2

Edited by BrandonW
Link to comment
Share on other sites

Your MsgBox was horribly wrong, be more careful with the function's parameters.

Take a look at this, is it better ? Are the source and destination correct for each computer name ?

$file = FileOpen("qsdeployed.txt", 0)

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $path = "c$\Documents and Settings\user\Start Menu\Programs\Quantitative Sentinel"
    $path2 = "c$\Documents and Settings\All Users\Start Menu\Programs"
    MsgBox (0, "Source :", "\\" & $line & "\" & $path, $line & "\" & $path2)
    MsgBox (0, "Destination :", $line & "\" & $path2)
    ;  If @error = -1 Then MsgBox (0, "", "Failed")
   ;  DirCopy($line & "\" & $path, $line & "\" & $path2, 0)
Wend
Edited by Inverted
Link to comment
Share on other sites

MsgBox (0, "Source :", "\\" & $line & "\" & $path)
    MsgBox (0, "Destination :", "\\" & $line & "\" & $path2)

I fixed those two lines and now the source/destination are both correct.

So I guess now for the DirCopy, what is the best way to combine the two? Should I setup some sort of variable for a source and destination path?

Link to comment
Share on other sites

This is correct ?

$source = "\\" & $line & "\" & $path

$dest = "\\" & $line & "\" & $path2

MsgBox showed everything to be correct! It's weird ... I was using DirCopy and it wouldn't work, but I had it set to 0 (not overwrite). Looking at the Help file I forgot there is a DirMove (which is moreso what I am doing) and I set it to 1 (overwrite, even though there won't be anything to overwrite) and it worked!

Inverted, thanks a bunch!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...