Created
November 25, 2015 10:48
-
-
Save nomadalex/fe7acd459e414096aa28 to your computer and use it in GitHub Desktop.
clean uploaded file and dirs after bypy syncup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "fileutils" | |
list_fn = ARGV[0] | |
root_dir = ARGV[1] | |
sames = [] | |
is_same_files = false | |
File.readlines(list_fn).each do |line| | |
line.chomp! | |
if line == "==== Same files ===" then | |
is_same_files = true | |
elsif line == "==== Different files ===" then | |
is_same_files = false | |
else | |
if is_same_files then | |
strs = line.split(" - ") | |
sames << File.join(root_dir, strs[1]) if strs[0] == "F" | |
end | |
end | |
end | |
sames.each do |s| | |
if File.exists?(s) then | |
puts "rm #{s}" | |
FileUtils.rm_f(s) | |
end | |
end | |
def walk_dir(dir) | |
entries = Dir.entries(dir).select { |e| e != "." && e != ".." } | |
count = entries.size | |
entries.each do |e| | |
e = File.join(dir, e) | |
if Dir.exists?(e) then | |
count = count-1 if walk_dir(e) | |
end | |
end | |
if count == 0 then | |
puts "rm -r #{dir}" | |
FileUtils.rm_r(dir) | |
true | |
else | |
false | |
end | |
end | |
walk_dir(root_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment