Adding a Line to a File

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Posts: 1
Joined: Fri Oct 19, 2012 8:11 am

Adding a Line to a File

Post by scriptnoob »

I am looking for a script to look in a folder and read each text file and check for a line. If it doesn't exist add that line to the beginning of the file, and if it does skip to the next file.

Posts: 14691
Joined: Tue May 22, 2007 9:57 am
Answers: 7
Has voted: 2 times
Been upvoted: 5 times

Adding a Line to a File

Post by jvierra »

Can you post your script?

What is it that is not working?

We do not write customcritps butyou can ask a question about any aspect of script writing.

In PowerSehll you can

$line='My line of text'
dir c:folder* |
?{select-string $_ $line |
$line |
Out-File $_ -append

This would do what you are after.