Re: Searching & editing all text files in a folder
- From: "\"Crash\" Dummy" <dvader@xxxxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 13:47:20 -0500
> 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.
--
Crash
.
- References:
- Searching & editing all text files in a folder
- From: Limbo
- Searching & editing all text files in a folder
- Prev by Date: Re: system error 85 has occured
- Next by Date: Re: Script a specific DNS setting for Client PCs
- Previous by thread: Searching & editing all text files in a folder
- Next by thread: Re: system error 85 has occured
- Index(es):
Relevant Pages
|
Loading