搜索和更改文件 [英] Searching and changing files

查看:71
本文介绍了搜索和更改文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想帮助创建一个程序来搜索某个扩展名的所有文件,并更改这些文件中的某些数据,实际上,我不知道如何.

例如:

更改所有*内的数据X.目录中的txt文件.

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. :)

推荐答案

对于Windows解决方案:

1.使用FindFirstFile和FindNextFile查找* .txt文件.这里是如何使用这些示例:http://msdn.microsoft.com/zh-cn/library/aa365200%28v=vs.85%29.aspx

2.找到* .txt文件后,将其打开;否则,请打开它.在这里您可以使用stdio或Win32 API.

3.循环读取大块文件,扫描要更改的文本,然后替换/删除它.

4.作为(3)的替代方法,将整个文件读入内存,进行扫描.

5.继续下一个文件.

6.转到(2).
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).


有一个简单的UNIX解决方案 ^ ].
There is a simple UNIX solution here[^].


这篇关于搜索和更改文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆