Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows Linux
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. Smile | :)
Posted 8-May-11 18:20pm
Edited 8-May-11 23:32pm
v3
Rate this: bad
good
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: 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).
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

There is a simple UNIX solution here[^].
  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 9 May 2011
Copyright © CodeProject, 1999-2014
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