Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I would like to help to create a program to search for all files of a certain extension, and change some data within those files, in fact, I do not know how.

For example:

Change the data X, which is within all *. txt files in a directory.

/
/test.txt
/test/test1.txt
/test/test1/test.txt
/test/test1/test1.txt
/test/test1/test2.txt
/eg/eg.txt
/eg/blah/eg1.txt

but as the list of files within that folder and sub​​-folders is very large, is to make the program look for these files, and change the data?

Thanks for the help. :)
Posted
Updated 8-May-11 22:32pm
v3

For a Windows solution:

1. Use FindFirstFile and FindNextFile to find *.txt files. Here's an example of how to use these: http://msdn.microsoft.com/en-us/library/aa365200%28v=vs.85%29.aspx

2. When you find a *.txt file, open it; here you can use stdio or Win32 APIs.

3. Loop to read the file in chunks, scan for the text you want to change, and substitute/delete it.

4. As an alternative to (3), read the whole file into memory, do the scan.

5. Continue to next file.

6. Go to (2).
 
Share this answer
 
There is a simple UNIX solution here[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900