Re: Searching & editing all text files in a folder
- From: "Limbo" <limbo2u@xxxxxxxxxxxx>
- Date: Thu, 1 Dec 2005 00:51:18 -0000
""Crash" Dummy" <dvader@xxxxxxxxxxxxx> wrote in message
news:OD3GVVR9FHA.2576@xxxxxxxxxxxxxxxxxxxxxxx
>> I need a script which would have a folder passed as an argument, and
>> would
>> then search all txt files in the folder for a specific string and then
>> delete the string if it exists.
>
>> The folders contain several thousand small text files.
>
>> Is this possible? Any pointers would be much appreciated.
>
> You don't say exactly how the target folder is "passed" to the script, so
> I just
> defined it as a text string at the start of the script, but I think the
> "meat"
> of the script is what you want.
>
> '---------------------------------
> target="d:\folder"
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set root=fso.getFolder(target)
> someString="Text you want to delete"
>
> for each file in root.files
> if file.type="Text Document" then
> Set textStream=file.OpenAsTextStream(1)
> data=textStream.readAll
> textStream.close
> data=replace(data,someString,"")
> Set textStream= file.OpenAsTextStream(2)
> textStream.write data
> textStream.close
> end if
> next
> '-----------------------------------
>
> I am assuming that all the "small text files" have the ".txt" extension
> and will
> be classified as "Text Document." If not, you'll have to do some other
> extension
> testing to verify the files.
That worked perfectly, thanks very much for your help.
.
- Prev by Date: help please! script to show user's not logged in for 3 months and Have Password Cannot Expire flag set
- Next by Date: Group Policy
- Previous by thread: help please! script to show user's not logged in for 3 months and Have Password Cannot Expire flag set
- Next by thread: Group Policy
- Index(es):
Relevant Pages
|