0的文件在我的控制檯應用程序,我用Directory.EnumerateFiles返回UWP
var allFiles = Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories).ToList();
返回一個文件夾中的每個文件的路徑(和所有子文件夾)。
但是在UWP,使用同樣的事情返回0
FolderPicker folderPicker = new FolderPicker();
folderPicker.SuggestedStartLocation = PickerLocationId.ComputerFolder;
folderPicker.FileTypeFilter.Add("*");
StorageFolder pickedFolder = await folderPicker.PickSingleFolderAsync();
var allFiles = Directory.EnumerateFiles(pickedFolder.Path, "*.*", SearchOption.AllDirectories).ToList();
我做了使用GetFilesAsync()
和GetFolderAsync()
功能的方法,但它是沒有在附近快如Directory.EnumerateFiles()
private async Task GetFilesInFolders(ObservableCollection<string> list, StorageFolder parent)
{
foreach (var file in await parent.GetFilesAsync())
{
list.Add(file.Path);
}
foreach (var folder in await parent.GetFoldersAsync())
{
await GetFilesInFolders(list, folder);
}
}
爲什麼Directory.EnumerateFiles()
返回0個文件?
你確定'directoryPath'和'pickedFolder.Path'是相同的嗎?你有沒有嘗試用相同的硬編碼字符串替換兩者來排除? –
@RufusL是的,我試過了,仍然是0 :( –