【问题标题】:How can I change file permissions with winjs如何使用winjs更改文件权限
【发布时间】:2014-10-15 00:40:12
【问题描述】:

我目前正在开发 Windows 8 winJS/AngularJS 应用程序,我们希望将一些存储在 LocalState 文件夹中的文件更改为只读权限。这些文件是用相机拍摄的图像,我们不鼓励在保存后更改图像。

任何想法都会很棒。我正在使用 Windows.Storage.StorageFile.getFileFromPathAsync() 来获取文件。

【问题讨论】:

    标签: angularjs windows-8.1 winjs


    【解决方案1】:

    您可以使用 StorageFile.properties.retrievePropertiesAsync 和 savePropertiesAsync 方法来执行此操作。这是一段使文件成为只读的代码,我在其中定义了在 Win32 API 中找到的只读属性:

    var key = "System.FileAttributes";
    var FILE_ATTRIBUTES_READONLY = 1;  //From the Win32 API
    
    var file;  
    
    //Assign some StorageFile to the file variable  
    file.properties.retrievePropertiesAsync([key]).then(function (props) {
         if (props) {
             props[key] |= FILE_ATTRIBUTES_READONLY;
         } else {
             props = new Windows.Foundation.Collections.PropertySet();
             props.insert(key, FILE_ATTRIBUTES_READONLY);
         }  
    
        return file.properties.savePropertiesAsync(props);
    }).done(function () {
        //Any other action
    });
    

    你可以像 Rob 所说的那样使用 WinRT 组件,但没有必要。

    我的免费电子书Programming Windows Store Apps with HTML, CSS, and JavaScript, Second Edition 第 11 章从第 592 页开始对文件属性进行了全面讨论。上面的代码直接来自第 601 页。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      • 1970-01-01
      • 2011-02-27
      • 2017-04-06
      • 2014-01-25
      • 2010-12-09
      相关资源
      最近更新 更多