Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. require 'shellwords'
  2.  
  3. # Dir.glob was acting weird w/ spaces in file names, so just used find:
  4. IO.popen("find Old\\ Home/apilsch/ -type f") do |fp|
  5. while not (output = fp.gets).nil?
  6. # Full file path:
  7. file = "/Users/apilsch/Desktop/#{output.strip}"
  8. # Location of original file on disk:
  9. disk_file = file.sub("Desktop/Old\ Home/apilsch/", "")
  10. next if not File.exist? disk_file
  11. # Similar to the problem w/ Dir.glob, File.stat was acting strange w/ spaces in file names, so just use commands:
  12. old_mode = %x(/usr/bin/stat -f '%A' #{Shellwords.escape(file)}).to_i
  13. new_mode = %x(/usr/bin/stat -f '%A' #{Shellwords.escape(disk_file)}).to_i
  14. if old_mode != new_mode
  15. puts "Changing #{disk_file} from #{new_mode} to #{old_mode}"
  16. # chmod the file:
  17. %x(/bin/chmod #{old_mode} #{Shellwords.escape(disk_file)})
  18. else
  19. puts "File #{disk_file} is fine"
  20. end
  21. end
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement