【问题标题】:Get an specific file from an specific folder从特定文件夹中获取特定文件
【发布时间】:2016-03-05 20:58:53
【问题描述】:

嗨,我正在做一个 Windows 8 Javascript 应用程序,你知道如何从 C:\Users\Me\Pictures\thifolder 获取文件名的 example2.dat 我尝试使用Windows.Storage.StorageFile.getFileFromPathAsync("C:\Users\Me\Pictures\thisfolder"); 但它没有用,因为我还有其他文件,例如 example1.dat、example3.dat example.jpg 等。

希望我说清楚了,提前谢谢

这是我目前的代码

    function here() {
        var getJsonStringAsync = function () {

            return   Windows.Storage.StorageFile.getFileFromPathAsync("C:\Users\Me\Pictures\thisfolder")   
//Also tried this
            //return Windows.Storage.KnownFolders.picturesLibrary.getFileAsync(u_u + "_" + u + "_" + ".dat")
                    .then(function (file) {
                        return Windows.Storage.FileIO.readTextAsync(file);
                    });
        };

        getJsonStringAsync().then(function (text) {
        document.getElementById("line").innerHTML = text;
    });
}

【问题讨论】:

  • 我也想获取文件夹内的文字,希望大家帮忙

标签: windows file windows-runtime directory winjs


【解决方案1】:

在图片库中读取文件的正确方法是这样的: (不要忘记在应用的清单中声明对图片库的访问权限)

var getJsonStringAsync = function () {
    var picturesLibrary = Windows.Storage.KnownFolders.picturesLibrary;
    return picturesLibrary.getFolderAsync("thisfolder").then(function (folder){
        return folder.getFileAsync("example2.dat").then(function (file) {
            return Windows.Storage.FileIO.readTextAsync(file);
        });
    });
};

【讨论】:

    【解决方案2】:

    在 JavaScript 中,如何播放音乐库中的“song.mp3”:

    HTML:

      <audio id="player1">Your browser does not support audio </audio>
    

    JavaScript:

            var ml = Windows.Storage.KnownFolders.musicLibrary;
                ml.getFileAsync("song.mp3").then(function (file) {
                    // its a storage file, so create URL from it
                    var s = window.URL.createObjectURL(file);
                    player1.setAttribute("src", s);
                    player1.play();
                //});
            });
    

    【讨论】:

      猜你喜欢
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2022-11-15
      相关资源
      最近更新 更多