Searching for Read-Only Files with Ruby

Wrote a quick ruby script that someone might find useful. It will recursively find and list readonly files from a passed in directory. There’s also a an array of file extensions you can exclude.

Nothing Fancy:

require 'find'

# update to exclude by file extension
exclude_extensions = ['.jpg','.txt','.png','.gif','.git']

if(ARGV[0] == nil) then
	puts "Please pass in a directory."
	exit
end

puts "Searching for NON read only files"

puts "Excluding: " + exclude_extensions.join("s")

writable = []
Find.find(ARGV[0]) do |path|

	if File.file?(path) and File.writable?(path) then
		if exclude_extensions.include?(File.extname(path))
			writable.push path
		end
	end
end


if writable.size then

	puts "Writable Files:"

	puts "t" + writable.join("nt")

else

	puts "No writable files."

end