Skip to content

Instantly share code, notes, and snippets.

@sgallese
Created May 15, 2010 18:57
Show Gist options
  • Save sgallese/402343 to your computer and use it in GitHub Desktop.
Save sgallese/402343 to your computer and use it in GitHub Desktop.
@path_to_repository = "/Users/claireharlam/Desktop/"
@repository_folder = "brown-digital-repository/"
@project_folder = "Screen/"
@file_count = 0
def recurse_dir( current_dir )
Dir.foreach( current_dir ) do |entry|
# Ignore the following files:
# . : self directory
# .. : parent directory
# .DS_Store : Mac OSX folder attrributes
# Icon? : Max OS Classic folder attributes
if (entry == "." ||
entry == ".." ||
entry == ".DS_Store" ||
entry == entry.scan(/Icon./)[0] )
else
@file_count += 1
data = Array.new
# Open the file in case we need to read it
current_file = File.new("#{current_dir+entry}")
# Path to file
relativepath = current_dir.split(@repository_folder)
relativepath[1] = @repository_folder + relativepath[1]
data.push(relativepath[1])
# Filename
data.push(entry)
# File extension
data.push(get_ext(entry))
# File mimetype
data.push(`file -Ib "#{current_dir+entry}"`.chomp)
# Convert size to kilobytes from 512 byte blocks
file_size = `ls -s "#{current_dir+entry}"`.to_i * 2
data.push(file_size)
# File creation time
data.push(current_file.ctime)
# File modification time
data.push(current_file.mtime)
# Extra file information
data.push(`file -b "#{current_dir+entry}"`.gsub(/(\r|\t|\n)/,' ' ) )
data.each do | text |
print "#{text}"
print "\t" if !text.eql?(data.last)
print "\n" if text.eql?(data.last)
end
if ( File::directory?( current_dir + entry ) )
recurse_dir(current_dir + entry + "/")
end
end
end
end
def get_ext( filename )
ext = ""
splitfile = filename.split(".")
if ( splitfile.length < 2 )
ext = "none"
elsif
ext = splitfile.pop()
end
return ext
end
recurse_dir(@path_to_repository + @repository_folder + @project_folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment