Link to home
Start Free TrialLog in
Avatar of fevster
fevster

asked on

Search for string in .cls file and then replace another string in that file

I want to search all .cls files in a directory and look for a string 'setcomplete' in each file. I then need to change another string in the file to a certain value depending on whether the 'setcomplete' is present or not.

What would be the best way to do this?

Thanks

fevster
Avatar of asafmm
asafmm

use InterDev Search dialog to search in your folder for your string - then doubleclick each file found and edit this file.
(U can use 'replace' too)
Avatar of fevster

ASKER

I want to try and automate this using my own VB program. So any code to help me do this would be great.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of drydenhogg
drydenhogg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Addendum:
I really should of used a proper comparison on the instring command
i.e. InStr(UCase$(objFile.Name), ".CLS") > 0
It works as is, that was rather lazy. :)
Avatar of fevster

ASKER

thats great thanks. Bit of a VB junior you see. Now that I can find my string in the file. I need to re-open the file to start reading again for the string to change. right??

How would I then change that string. Use replace or would I have to write the whole file out line by line??

Cheers
Brute force again would be to just read each line in turn and write out each line until you find the line to adjust. In that instance you write out your adjusted line.

Write it to a diff file, a.) it makes your life easier b.) you probs want to keep original files for the 'just-in-case' scenarios

Equally, could read the entire file into a string using the strFileTextStream.ReadAll and use the VB6 replace command.
Then write it to a file.

All depends on the nature of the string being replaced, as to whether you can use the replace command with confidence that it wont replace things you didnt plan.

ADH.
Avatar of fevster

ASKER

thanks for the help... it'll be a great help