我正在尝试将应用包文件夹复制到隔离存储。这就是我带来的。我得到一个javascript错误无法创建已存在的文件。我无法遍历子文件夹。
var root = Windows.ApplicationModel.Package.current.installedLocation;
copySubDirectories(root);
function copySubDirectories(subFolder) {
currentFolder.createFolderAsync(subFolder.name).done(function (newFolder1) {
subFolder.getFilesAsync().done(function (fileList1) {
if (fileList1==null) {
subFolder.getFoldersAsync().done(function (folderList1) {
folderList1.forEach(function (subFolder2) {
currentFolder = newFolder1;
copySubDirectories(subFolder2);
});
});
return;
}
fileList1.forEach(function (subFile1) {
subFile1.copyAsync(newFolder1, subFile1.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function () {
subFolder.getFoldersAsync().done(function (folderList1) {
folderList1.forEach(function (subFolder2) {
currentFolder = newFolder1;
copySubDirectories(subFolder2);
});
});
});
});
});
});
}
}
答案 0 :(得分:0)
我将文件列表和文件夹列表混合在一起导致应用程序崩溃。为每个流程创建功能是解决方案。
var sourceFolder = Windows.ApplicationModel.Package.current.installedLocation;
var destinationFolder = Windows.Storage.ApplicationData.current.localFolder;
copyDirectories(sourceFolder,destinationFolder);
function copyFiles(source, destination) {
source.getFilesAsync().done(function (fileList) {
if (fileList.size >= 1) {
fileList.forEach(function (subFile) {
subFile.copyAsync(destination, subFile.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function () { });
});
}
});
}
function copyDirectories(source,destination){
source.getFoldersAsync().done(function (folderList) {
if(folderList.size>1){
folderList.forEach(function (subFolder) {
destination.createFolderAsync(subFolder.name).done(function (newFolder) {
copyFiles(subFolder, newFolder);
copyDirectories(subFolder,newFolder);
});
});
}
});
}