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.
Locked
User avatar
scriptnoob
Posts: 1
Joined: Fri Oct 19, 2012 8:11 am

Adding a Line to a File

Post by scriptnoob » Fri Oct 19, 2012 8:11 am

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.

User avatar
jvierra
Posts: 13677
Joined: Tue May 22, 2007 9:57 am
Contact:

Adding a Line to a File

Post by jvierra » Fri Oct 19, 2012 10:18 am

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.

Locked