Created
February 21, 2014 17:40
-
-
Save ig10/9139100 to your computer and use it in GitHub Desktop.
Search & Destroy IMG's
This file contains hidden or 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/ruby | |
| # -*- encoding : utf-8 -*- | |
| #Author: Ignacio Diez (i10) | |
| #Date: July 14, 2012 | |
| puts "Eliminando Imagenes del Comparador\n====================================\n > Seleccione Sistema Operativo:\n" | |
| puts " 1 - Mac\n 2 - Ubuntu" | |
| raiz = {1 => "users", 2 => "home"} | |
| so = 0 | |
| until so.is_a?(Fixnum) and so.between?(1,2) | |
| so = gets.chomp.to_i | |
| end | |
| user = %x[whoami].chop | |
| ruta = "/#{raiz[so]}/#{user}/comparador" | |
| puts "Seleccione Directorio: \n" | |
| dirs = Dir["#{ruta}/public/images/*/"] | |
| dirs.each_with_index do |d,i| | |
| puts "#{i+1} - #{d.split('/').last}" | |
| end | |
| seleccion = "" | |
| until seleccion.is_a?(Fixnum) and seleccion >= 0 | |
| seleccion = gets.chomp.to_i - 1 | |
| end | |
| unless dirs[seleccion].nil? | |
| puts "Inspeccionando Imagenes de [ #{dirs[seleccion]} ]\n" | |
| archivos = %x[ls -R #{dirs[seleccion]}].split("\n").select{|i| i =~ /\./} | |
| archivos.each do |a| | |
| unless system("grep -r #{a} #{ruta}/app > /dev/null") | |
| #Eliminar IMG | |
| file = %x[find #{dirs[seleccion]} -name #{a}].split("\n") | |
| unless file.empty? | |
| file.each do |f| | |
| confirma = "" | |
| until %w(s y n).include?confirma do | |
| puts "¿Seguro que deseas borrar el archivo\n\t[[ #{f} ]] ? (s/n)" | |
| confirma = gets.chomp.downcase | |
| end | |
| if ["s","y"].include?confirma | |
| File.delete(f) | |
| puts "Archivo [ #{a} ] Eliminado." | |
| else | |
| puts "No se ha eliminado el archivo [ #{a} ]." | |
| end | |
| end#file.each | |
| end#unless file.empty? | |
| else | |
| puts "[ #{a} ] archivo está actualmente en uso" | |
| end | |
| end | |
| end | |
| puts "Proceso de Eliminacion Finalizado." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment