Answered by:
Iterate through directory Windows 8 Apps

Question
-
Hello,
I am trying to recursively iterate through a directory for a c++ windows 8 App, I've tried 3rd party API's which fail certification and headers such as dirent.h are not available. Is there a better option to iterate through a directory to get a list of files and subdirectories than using StorageFolder/File?
Wednesday, August 14, 2013 10:13 PM
Answers
-
Where is the directory you are enumerating?
Your app has permissions to read its app install and to read and write its app data directory. It can use standard C runtime functions to iterate through these directories.
Your app doesn't have permissions to access other directories and must use the file broker via the StorageFolder and StorageFile classes.
--Rob
- Marked as answer by Xiaoliang Chen - MSFTModerator Wednesday, August 21, 2013 12:48 AM
Thursday, August 15, 2013 12:02 AMModerator -
Whoops. You're right. There is no standard C or C++ implementation for directories, only for files.
You will need to use OS provided API, which for Windows Store apps means StorageFolder. You can use C runtime functions such as fopen on the files within the folder.
--Rob
- Marked as answer by Xiaoliang Chen - MSFTModerator Wednesday, August 21, 2013 12:48 AM
Thursday, August 15, 2013 12:21 AMModerator
All replies
-
Where is the directory you are enumerating?
Your app has permissions to read its app install and to read and write its app data directory. It can use standard C runtime functions to iterate through these directories.
Your app doesn't have permissions to access other directories and must use the file broker via the StorageFolder and StorageFile classes.
--Rob
- Marked as answer by Xiaoliang Chen - MSFTModerator Wednesday, August 21, 2013 12:48 AM
Thursday, August 15, 2013 12:02 AMModerator -
It is trying to access the apps root sub-directory that it is installed on, it just reads the files/directories and prints a list, I have tried using DIR and dirent to access these directories as well as other methods within the 3rd party BOOST library such as FindFirstFileW, etc... the following location I am trying to access is a sub-directory of: Windows::ApplicationModel::Package::Current->InstalledLocation
Thursday, August 15, 2013 12:12 AM -
Whoops. You're right. There is no standard C or C++ implementation for directories, only for files.
You will need to use OS provided API, which for Windows Store apps means StorageFolder. You can use C runtime functions such as fopen on the files within the folder.
--Rob
- Marked as answer by Xiaoliang Chen - MSFTModerator Wednesday, August 21, 2013 12:48 AM
Thursday, August 15, 2013 12:21 AMModerator -
Ah got it, so basically the only way it would be able to do this is if I use something like:
StorageFolder ^ currentDirectory = StorageFolder::GetFolderFromPathAsync(newBasePath);
and also somehow (like c#) would need to await this method (except in c++ there is no await)
Then use: auto currentDirectoryEntries = currentDirectory->getFilesAsync();
To return all files and iterate that way... are there methods to tell if it is a File/Directory like: S_ISDIR/S_ISREG?
Thursday, August 15, 2013 12:28 AM