Reputation: 40678
How can I programmatically change a file's permission to be writable?
The input are read-only files, and I want to know if there is a general a way to guarantee that I can turn on writability/turn off read-only, no matter what version of Windows (XP, server-2003, or higher).
Upvotes: 3
Views: 1950
Reputation: 1
Here's another way. Install cygwin on your windows system Then access your folder using
cd /cygdrive/c/
Then use chmod for changing permissions.
Upvotes: 0
Reputation: 40678
FileUtils.chmod 'a+x', %w(foo.txt bar.txt)
That is based off of @Arup's comment of using http://ruby-doc.org/stdlib-2.0.0/libdoc/fileutils/rdoc/FileUtils.html#method-c-chmod -- which works for me, and it stays in pure ruby.
Upvotes: 2
Reputation: 80085
The read-only attibute in Windows is set with the attrib command.
exec "attrib +R 12345.jpg" #sets the read-only file attribute
exec "attrib -R 12345.jpg" #removes the read-only file attribute
Upvotes: 2