JOEZACK.COM Code Musings and Such

1Sep/100

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("\n\t")

else

	puts "No writable files."

end
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Tagged as: Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.