2017-10-09 48 views
0

以下列出了應用程序中的「資產」文件夾中的文件並正確運行。音樂庫文件夾中的uwp javascript列表文件

// Get the path to the app's Assets folder. 
var root = Windows.ApplicationModel.Package.current.installedLocation.path; 
var path = root + "\\Assets"; 
//var path = Windows.Storage.KnownFolders.musicLibrary; 
var StorageFolder = Windows.Storage.StorageFolder; 
var folderPromise = StorageFolder.getFolderFromPathAsync(path); 
folderPromise.done(function getFolderSuccess(folder) { 
    var filesInFolderPromise = folder.getFilesAsync(); 
    filesInFolderPromise.done(function getFilesSuccess(filesInFolder) { 
     s = ""; 
     filesInFolder.forEach(function forEachFile(item) { 
      s = s + item.name + "<br />"; 
     }); 
     document.getElementById('filelist').innerHTML = s; 
    }); 
}); 

我想修改它以列出musicLibrary中的文件。當我改變的路徑名

var path = Windows.Storage.KnownFolders.musicLibrary; 

我得到

JavaScript runtime error: The parameter is incorrect 

請幫我用適當的語法。音樂庫功能在清單中設置。

回答

1

目的是從音樂文件夾獲取文件異步。這是直接完成如下:

var f = Windows.Storage.KnownFolders.musicLibrary; 
f.getFilesAsync().done(function getFilesSuccess(filelist) { 
    s = ""; 
    filelist.forEach(function forEachFile(item) { 
     s = s + item.name + "<br />"; 
    }); 
    document.getElementById('filelist').innerHTML = s; 
}); 

感謝pnp0a03,並快速重新閱讀文檔。

0

對於那些語法掙扎,這個答案是相同的:

var f = Windows.Storage.KnownFolders.musicLibrary; 
f.getFilesAsync().then(success42); 
function success42(filelist) { 
    s = ""; 
    filelist.forEach(function forEachFile(item) { 
     s = s + item.name + "<br />"; 
    }); 
    document.getElementById('filelist').innerHTML = s; 
}