Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'json'
- # Position of the mounted drive
- $SOURCE = "/Volumes/GoogleDrive/Il mio Drive"
- # Destination of the json file
- $DEST = "/tmp/result.json"
- # Size for "too big" files
- $XGB = 2
- # Regular expression for drive files
- $REGEXPDRIVE = /^(.*)\.(gdoc|gsheet|gslides|gform|gscript)$/i
- #######
- $FILE_COUNT = 0
- $DIR_COUNT = 0
- $DATA = {
- "export" => {
- "gdoc" => [],
- "gsheet" => [],
- "gslides" => [],
- "gform" => [],
- "gscript" => []
- },
- "big" => [],
- "big_n" => 0,
- "copy" => [],
- "copy_n" => 0
- }
- def handle_dir(input, cwd)
- $DIR_COUNT += 1
- Dir.foreach(input) do |entry|
- next if entry == '..' or entry == '.'
- if File.file? entry
- $FILE_COUNT += 1
- if match = entry.match($REGEXPDRIVE)
- $DATA["export"][match[2]] << "#{cwd}/#{match[1]}"
- next
- end
- if (File.open(entry).size * 1e-9) > $XGB
- $DATA["big"] << "#{cwd}/#{entry}"
- $DATA["big_n"] += 1
- next
- end
- $DATA["copy"] << "#{cwd}/#{entry}"
- $DATA["copy_n"] += 1
- elsif File.directory? entry
- Dir.chdir(entry) do
- handle_dir(".", "#{cwd}/#{entry}")
- end
- else
- puts "ENTRY UNKNOWN :: #{cwd}/#{entry}"
- end
- end
- end
- Dir.chdir($SOURCE) do
- handle_dir(".", ".")
- end
- File.open($DEST, "w") do |f|
- f.puts JSON.generate($DATA, indent: ' ', max_nesting: false)
- end
- puts "STATISTICS:"
- puts " - total dirs: #{$DIR_COUNT}"
- puts " - total files: #{$FILE_COUNT}"
- puts " - drive docs: #{$DATA["export"]["gdoc"].size}"
- puts " - drive sheet: #{$DATA["export"]["gsheet"].size}"
- puts " - drive form: #{$DATA["export"]["gform"].size}"
- puts " - drive slides: #{$DATA["export"]["gslides"].size}"
- puts " - drive scripts: #{$DATA["export"]["gscript"].size}"
- puts " - direct copy: #{$DATA["copy_n"]}"
- puts " - big files: #{$DATA["big_n"]}"
Add Comment
Please, Sign In to add comment