Cra*_*ezz 6 c# copy windows-8 winrt-async
现在,我只知道如何使用以下方法复制文件:
IStorageFolder dir = Windows.Storage.ApplicationData.Current.LocalFolder;
IStorageFile file = await StorageFile.GetFileFromApplicationUriAsync(
new Uri("ms-appx:///file.txt"));
await file.CopyAsync(dir, "file.txt");
Run Code Online (Sandbox Code Playgroud)
当我尝试复制文件夹和里面的所有内容时,我找不到CopyAsync上面的API .
是否可以复制文件夹和WinRT中的所有内容?
Jér*_* S. 10
上面的代码不满足我(太具体),我制作了我自己的通用代码,所以我想可以分享它:
public static async Task CopyFolderAsync(StorageFolder source, StorageFolder destinationContainer, string desiredName = null)
{
StorageFolder destinationFolder = null;
destinationFolder = await destinationContainer.CreateFolderAsync(
desiredName ?? source.Name, CreationCollisionOption.ReplaceExisting);
foreach (var file in await source.GetFilesAsync())
{
await file.CopyAsync(destinationFolder, file.Name, NameCollisionOption.ReplaceExisting);
}
foreach (var folder in await source.GetFoldersAsync())
{
await CopyFolderAsync(folder, destinationFolder);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3376 次 |
| 最近记录: |