Last active
June 3, 2017 20:55
-
-
Save b-coimbra/6fe81b3067b2767d5d39cbe341bc7ccb to your computer and use it in GitHub Desktop.
sort files numerically in increasing order
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 | |
->(i) {->(_) {Dir[$_=(_.nil? ? '.' : _) + '/*'].each_with_index {|f,i| f.to_enum(:scan, /(?<type>\.(png|jpg|jpeg|gif|webm|mp4|pdf))$/im). \ | |
map {p "[#{-~i}/#{Dir["#{_}/*"].length}] "+f;$_=f; test(?e, ($_) + i.to_s + $1) ? next : \ | |
File.rename(f, File.dirname(f) + File::SEPARATOR + (-~i).to_s + $~[:type])}}} \ | |
::(ARGV[0])}.(0) && at_exit {system "echo Done! && explorer #{$_.gsub(/\/[(\w|\d)\.\w\d]+$/i,'')}"} \ | |
rescue Errno::EACCESS abort "Cant sort this folder :(" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment