Clock
Clock

Reputation: 984

Check if a file is directory in UWP

In my old WPF app I was having a code like:

bool isDirectory = File.GetAttributes(filePath).HasFlag(FileAttributes.Directory);

to check if a file is a directory or not, and this was working perfectly fine.

Now I try to migrate my project to UWP and I am getting this error:

System.InvalidOperationException: 'Synchronous operations should not be performed on the UI thread. Consider wrapping this method in Task.Run

I was trying to solve it and read more about it, but no useful information was found.

Do you know which is the UWP equivalent for my old WPF code line, so how could I check if a file from the disk is a directory or an actual file in UWP ?

Upvotes: 0

Views: 196

Answers (1)

Michael S. Scherotter
Michael S. Scherotter

Reputation: 10785

If the UWP has permissions to access the item, Get the parent folder as a StorageFolder and then call the StorageFolder.TryGetItemAsync API. Then call IStorageItem.IsOfType on the result.

Upvotes: 1

Related Questions