Reputation: 147
I am writing a file system program in C++. Now I try to write a file finding function. First I want program be able to search the file in all system. I use FindFirstFile and FindNextFile Windows API functions. First I should call FindFirstFile , and give it the directory, where it must search the file. But I don't know, how to specify the diirectory so that FindFirstFile searches in all the system. Please, help me with that question. I will be very grateful for any help.
Upvotes: 1
Views: 518
Reputation: 29724
this is what I've found here:
you cannot use a trailing backslash () in the lpFileName input string for FindFirstFile, therefore it may not be obvious how to search root directories. If you want to see files or get the attributes of a root directory, the following options would apply: To examine files in a root directory, you can use
"C:\*"
and step through the directory by using FindNextFile. To get the attributes of a root directory, use the GetFileAttributes function. Note Prepending the string "\?\" does not allow access to the root directory.
to get a list of available drives you might use GetLogicalDriveStrings()
. This returns a double-null terminated list of null-terminated strings. E.g., say you had drives A, B
and C
in your machine. The returned string would look like this:
A:\<nul>B:\<nul>C:\<nul><nul>
https://stackoverflow.com/a/18573199/1141471
Upvotes: 1