how to search for a file in all drives

﹥>﹥吖頭↗ 提交于 2020-01-16 05:37:06

问题


hey how can i search for a file in HDD ,

example i wanna search for a file settings.ini in my computer .


回答1:


First you have to get a list of valid drives. This was discussed previously on the StackOverflow.

The you have to call FindFirst/FindNext/FindClose on the root folder of each drive. Get a list of files and directories. Check the list of files. Repeat this for each directory. Until you run out of directories. Search for "[delphi] findfirst" on StackOverflow to find more information.




回答2:


Just adding to the FindFirst/FindNext advice:

Take care with the "." and ".." directory names that come back. Otherwise, you may never run out of items to walk.

Also keep watch for anything coming back, in the WIN32_FIND_DATA result, with the FILE_ATTRIBUTE_REPARSE_POINT flag set. That'll probably be a symlink, and where it goes might also give you an infinite walk. An example can be seen over at the Old New Thing.



来源:https://stackoverflow.com/questions/1740561/how-to-search-for-a-file-in-all-drives

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!