我想清理winrt中storageFolder.RoamingFolder的所有文件 我可以删除单个文件但是。对于如何处理这个问题没有任何想法?
答案 0 :(得分:3)
如果你想要实现删除文件夹的内容,那么这样的递归方法就可以了:
public static async Task DeleteFolderContentsAsync(StorageFolder folder,
StorageDeleteOption option)
{
// Try to delete all files
var files = await folder.GetFilesAsync();
foreach (var file in files)
{
await file.DeleteAsync(option);
}
// Iterate through all subfolders
var subFolders = await folder.GetFoldersAsync();
foreach (var subFolder in subFolders)
{
// Delete the contents
await DeleteFolderContentsAsync(subFolder, option);
// Delete the subfolder
await subFolder.DeleteAsync(option);
}
}