如何以编程方式将文件权限更改为可写?
输入是只读文件,我想知道是否有一种通用的方法可以保证我可以打开可写性/关闭只读,无论Windows版本是什么(XP、server-2003或更高版本)。
如何以编程方式将文件权限更改为可写?
输入是只读文件,我想知道是否有一种通用的方法可以保证我可以打开可写性/关闭只读,无论Windows版本是什么(XP、server-2003或更高版本)。
在Windows中,只读属性是通过使用attrib命令来设置的。
exec "attrib +R 12345.jpg" #sets the read-only file attribute
exec "attrib -R 12345.jpg" #removes the read-only file attribute
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,这对我很有效,并且它保持了纯粹的Ruby。