Click here to Skip to main content
13,143,693 members (30,284 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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.


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 8-May-11 17:20pm
Updated 8-May-11 22:32pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

For a Windows solution:

1. Use FindFirstFile and FindNextFile to find *.txt files. Here's an example of how to use these:

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).
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

There is a simple UNIX solution here[^].

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 9 May 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100