【问题标题】:How do I change file permissions on Windows?如何在 Windows 上更改文件权限?
【发布时间】:2013-12-30 00:30:50
【问题描述】:

如何以编程方式将文件的权限更改为可写?

输入的是只读文件,我想知道是否有一种通用的方法可以保证我可以打开可写性/关闭只读,无论是什么版本的Windows(XP,server-2003 ,或更高)。

【问题讨论】:

  • 啊,我没有意识到我可以传递字符而不仅仅是位图......
  • 你试过什么? Stack Overflow 希望你展示你尝试过的东西,所以我们知道什么不能重复。这也很有帮助,因为我们可以纠正你的错误,而不是写一些与你以前的工作无关的东西,然后你必须把它硬塞起来。

标签: ruby windows file-permissions


【解决方案1】:

Windows 中的只读属性设置为attrib command

exec "attrib +R 12345.jpg" #sets the read-only file attribute
exec "attrib -R 12345.jpg" #removes the read-only file attribute

【讨论】:

    【解决方案2】:
    FileUtils.chmod 'a+x', %w(foo.txt bar.txt)
    

    这是基于@Arup 使用http://ruby-doc.org/stdlib-2.0.0/libdoc/fileutils/rdoc/FileUtils.html#method-c-chmod 的评论——这对我有用,并且它保留在纯红宝石中。

    【讨论】:

    • 您也可以在答案中编写实际代码,以便其他人提供帮助。
    猜你喜欢
    • 1970-01-01
    • 2016-10-10
    • 2012-05-05
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 2015-04-14
    • 2012-07-14
    相关资源
    最近更新 更多