开发者

Iterating files in a directory without using FindFirstFile

On the Windows operating system, how do you iterate the files in a given directory without the use of third-party libraries or the us开发者_StackOverflowe of FindFirstFile, FindNextFile, etc?


Given that FindFirstFile is the main file enumeration method in Windows, what else do you expect to get? There are NT API functions (ZwQueryDirectoryFile and similar), which are called by FindFirstFile, but they are more complicated and don't give real benefit.


If you are able to use managed code the programming is a little easier with Directory.EnumerateFiles.

Returns an enumerable collection of file names in a specified path.


The only additional way which i know to list the files in a directory is using the Scripting.FileSystemObject object which is part of the Windows Scripting library. you can use this object in C++, delphi or any language which supports access to COM.

check this sample code in vbscript

Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\test"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
    Wscript.Echo objFile.Name
Next
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜