Skip to content

Instantly share code, notes, and snippets.

@kalabiyau
Created August 24, 2011 15:18
Show Gist options
  • Save kalabiyau/1168295 to your computer and use it in GitHub Desktop.
Save kalabiyau/1168295 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
module DocSorter
extend self
require 'ap'
DOC = %w{doc docx xls odt xlsx dwg txt cdr psd ppt eml csv log xslic}
CODE = %w{yml sql mht htm html php rb diff conf}
PDF = %w{pdf}
GRAPH = %w{tiff jpg jpeg bmp gif png}
ARH = %w{zip rar 7z gz tgz bz2 bz exe jnlp msi apk xpi gem ipsw}
EXE = %w{exe msi}
ISO = %w{iso deb}
MUZ = %w{mp3 wav flac rm}
TORRENTS = %w{torrent}
BOOKS = %w{azw mobi epub}
@consts = DocSorter.constants
COLORS = [:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white, :black, :redish, :greenish, :yellowish, :blueish, :purpleish, :cyanish, :pale]
@dowsdir = '/home/achernikov/Downloads'
@files_by_types = {}
@consts.each {|con| @files_by_types.merge!(con.to_s.downcase.to_sym=>[]) }
def files_scan
puts "Processing #{@dowsdir} directory"
@files = Dir["#{@dowsdir}/*"].delete_if {|f| not File.file?(f)}
puts "We have #{@files.count} files in target dir"
@consts.each do |const|
eval(const.to_s).each do |type|
@files.map do |file|
if file =~ /#{type}$/i
@files_by_types[const.to_s.downcase.to_sym] << file
end
end
end
end
end
files_scan
@files_by_types.each_value {|val| val.each {|x| @files.delete(x)}}
@files_by_types.each {|ftf| ap ftf, :color => {:string => COLORS.delete(":red") {COLORS}.sample}}
ap @files, :color => {:string => :red}, :indent => 20
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment