Click here to Skip to main content
Rate this: bad
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
0 CHill60 380
1 Sergey Alexandrovich Kryukov 245
2 Richard MacCutchan 152
3 CPallini 150
4 Peter Leow 150
0 Sergey Alexandrovich Kryukov 9,193
1 OriginalGriff 6,786
2 Peter Leow 4,332
3 Zoltán Zörgő 3,809
4 Richard MacCutchan 2,672

Advertise | Privacy | Mobile
Web03 | 2.8.150128.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