Click here to Skip to main content
11,925,307 members (56,615 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ Windows Linux

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. Smile | :)
Posted 8-May-11 18:20pm
Edited 8-May-11 23: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 | Mobile
Web02 | 2.8.151126.1 | Last Updated 9 May 2011
Copyright © CodeProject, 1999-2015
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