Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'shellwords'
- # Dir.glob was acting weird w/ spaces in file names, so just used find:
- IO.popen("find Old\\ Home/apilsch/ -type f") do |fp|
- while not (output = fp.gets).nil?
- # Full file path:
- file = "/Users/apilsch/Desktop/#{output.strip}"
- # Location of original file on disk:
- disk_file = file.sub("Desktop/Old\ Home/apilsch/", "")
- next if not File.exist? disk_file
- # Similar to the problem w/ Dir.glob, File.stat was acting strange w/ spaces in file names, so just use commands:
- old_mode = %x(/usr/bin/stat -f '%A' #{Shellwords.escape(file)}).to_i
- new_mode = %x(/usr/bin/stat -f '%A' #{Shellwords.escape(disk_file)}).to_i
- if old_mode != new_mode
- puts "Changing #{disk_file} from #{new_mode} to #{old_mode}"
- # chmod the file:
- %x(/bin/chmod #{old_mode} #{Shellwords.escape(disk_file)})
- else
- puts "File #{disk_file} is fine"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement