Click to See Complete Forum and Search --> : How do I find a directory, search for a word and replace in VB


lansdown
04-06-2001, 05:14 PM
How would I go about for example searching the c:\ directory on a computer for a file, finding a word or line and replace it with another within that file. So it is the equivalent of a find and replace.

Nick_B
04-06-2001, 05:22 PM
Originally posted by lansdown:
How would I go about for example searching the c:\ directory on a computer for a file, finding a word or line and replace it with another within that file. So it is the equivalent of a find and replace.

What type of file are you looking for? Do you already know the file name or is the program supposed to search all the files for the text to replace?

------------------
Nick_B
ICQ: 1697810
P4 1.4 GHz
256 Megs PC800 RDRAM
GeForce2 Ultra
Win 2K

lansdown
04-06-2001, 05:25 PM
I already have a module that finds and replaces a certain line in a file. I have to type in the file location, name and what to replace it with. I was wondering how I could search to see if the file exists on the computer and then see if a certain line exists and replace it or certain words within it.

Nick_B
04-06-2001, 06:32 PM
Originally posted by lansdown:
I already have a module that finds and replaces a certain line in a file. I have to type in the file location, name and what to replace it with. I was wondering how I could search to see if the file exists on the computer and then see if a certain line exists and replace it or certain words within it.

You could probably put together something like this using the FileSystemObject. The easiest way I can see to do it (it wouldn't be very efficient) would be to use the object to check for the file in the root of the first drive. Then to check in all the subfolders and each of there subfolders as well. Then move on to the next drive. I really don't have the experience to suggest something easier to perform. I don't have time today to look at it, but if you are still interested on Monday, I can take a closer look. Good Luck.

------------------
Nick_B
ICQ: 1697810
P4 1.4 GHz
256 Megs PC800 RDRAM
GeForce2 Ultra
Win 2K

[This message has been edited by Nick_B (edited April 06, 2001).]

Boldy
04-07-2001, 02:52 PM
If you have the code to open the file and replace the string, all you need is the code to find the file. You can use the DIR() function to find all files and subfolders of a given folder. Then you can set up a recursive routine to iterate through all the subfolders.

While there are many ways to do this, this link will show you one of them: http://www.vb2themax.com/Item.asp?PageID=CodeBank&Cat=140&ID=162

Hope this helps.

lansdown
04-09-2001, 11:19 AM
This looks like a great reference sight for code. I think it will help alot I am going to look around a bit.

Thanks

Nick_B
04-09-2001, 04:02 PM
Originally posted by Boldy:
If you have the code to open the file and replace the string, all you need is the code to find the file. You can use the DIR() function to find all files and subfolders of a given folder. Then you can set up a recursive routine to iterate through all the subfolders.

While there are many ways to do this, this link will show you one of them: http://www.vb2themax.com/Item.asp?PageID=CodeBank&Cat=140&ID=162

Hope this helps.

Yeah, that looks better and easier than what I was suggesting.

------------------
Nick_B
ICQ: 1697810
P4 1.4 GHz
256 Megs PC800 RDRAM
GeForce2 Ultra
Win 2K