question

MGBhadurudeen-1345 avatar image
0 Votes"
MGBhadurudeen-1345 asked MGBhadurudeen-1345 commented

How to access hidden files, folders without using broadFileSystemAccess?

Hi, I am developing an app that should enumerate all the files including hidden files and folders from a StorageFolder object. So far, I am unable to see any solution, without the broadFileSystemAccess. Since it is a rescap, I want to avoid this, I don't want my app rejected during certification. Is there any way to achieve this without using the broadFileSystemAccess? Thanks in advance.

windows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AryaDing-MSFT avatar image
0 Votes"
AryaDing-MSFT answered MGBhadurudeen-1345 commented

Hi,

Welcome to Microsoft Q&A!

Where is your folder? If your folder location is Application install directory or AppData locations that uwp app can access by default, you could use the DirectoryInfo class under System.IO namespace to enumerate all the files including hidden files and folders. As follows:

         var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
         DirectoryInfo diSource = new DirectoryInfo(folder.Path);
         foreach (var file in diSource.GetFiles()) {

             Debug.WriteLine(file.Name); //print file name
         }
         Debug.WriteLine("*************************");

         var directoryInfos= diSource.GetDirectories();
         foreach (var info in directoryInfos) {
             Debug.WriteLine(info.Name); //print folder name
         }

In addition, maybe you misunderstood the usage of broadFileSystem capability, this capability applies to the Storage API, but StorageFolder.GetFilesAsync() method can’t access the hidden file.

Therefore, my suggestion is that you could use DirectoryInfo class to access these two default location that uwp app can access. If you do want to access other file locations, maybe you need to create a win32 Console app and use DirectoryInfo class to enumerate files, then use packaging projects reference this console app and a uwp app. Finally, you could call this app from uwp app to achieve your requirement.




If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Where is your folder?

Thank you for your reply. I don't want to access my app's [installed location][1] or the [LocalFolder][2] of my app.
I want to access the folders outside of these two locations, for example, desktop, or D:\some or E:\some folders.
I use the FilePicker to get access to a folder picked by the user. But I am unable to retrieve the hidden files and folders from that picked folder. That's why I asked this question.

StorageFolder.GetFilesAsync() method can’t access the hidden file.

Ok. No issue. My requirement is only to access the hidden files and folders. StorageFolder.GetFilesAsync() is not my requirement.
If that can't do the task, I would like to know the solution by other APIs.


[1]: https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.package.installedlocation?view=winrt-19041
[2]: https://docs.microsoft.com/en-us/uwp/api/windows.storage.applicationdata.localfolder?view=winrt-19041
0 Votes 0 ·

If you do want to access other file locations, maybe you need to create a win32 Console app and use DirectoryInfo class to enumerate files, then use packaging projects reference this console app and a uwp app. Finally, you could call this app from uwp app to achieve your requirement.

1) Why should I create Win32 Console app to use the DirectoryInfo class?
2) Can the regular UWP app not do this job? Any advantage over the regular UWP app?
3) Or don't I need any special capabilities or permissions to use the DirectoryInfo class in the Win32 Console app?


0 Votes 0 ·

@MGBhadurudeen-1345

1.Uwp app has permission limitation, DirectoryInfo class can only access the two specified location. But if you use DirectoryInfo class in Win32 console app, it can’t be limited.

2.Uwp app can’t do this job. Without declaring capability, you could enumerate all files and folders whose attribute isn’t hidden in a folder through FolderOpenPicker. But the hidden file can’t enumerate.

3.Yes, in Win32 Console app, you could use DirectoryInfo class to access all location

0 Votes 0 ·

Thank you for your reply, along with a new idea. The 'packaging projects'. I searched, but could not get doc links. Please post any documentation links about this.

0 Votes 0 ·