Not an everyday task...

Over the years I have acquired a heaping pile of black and white eps files. I love them... they are simple little pieces of art, easy to re-purpose for all kinds of designs. However finding a file that would fit a design was never so easy. Each file was stored away into multiple subfolders having a numeric naming convention which repeated by folder. There were close to 500 or so folders with about 12-50 files per folders. Since all file names were numeric the only one way to find what you were looking for was browsing with adobe bridge. Clicking in and out of folder just became a pain.

I have been putting off the chore of either a) finding a script or program to move and rename my files b) writing a script to move and rename files. Tonight I went with plan b. I am sure there is something out there for plan a, I just couldn’t find it quick enough for me to not go ahead with plan b. Loading up irb I used ruby with the help of the FileMagick gem. Below you will see a not so elegant way to copy a set of files in ruby to the parent directory.

#navigate to the directory of where your files exsit #load irb #int inew directory d=Dir.new('.') #require the following libs require 'filemagic' require 'ftools' # loop directories d.entries.each do |f| if fm.file(f.to_s).eql? 'directory' f.each do |sub| next if sub =~ /^\.\.?$/ dh = Dir.open(sub) Dir.chdir(sub.to_s) # enter subdirectory puts Dir.pwd dh.each do |file| next if file =~ /^\.\.?$/ puts "Copy File: #{file.to_s}, ../#{sub}_#{file}" File.copy(file,"../#{sub}_#{file}") # copy file to parent directory end Dir.chdir("..") puts Dir.pwd end end end

Related: http://pleac.sourceforge.net/pleac_ruby/directories.html

Post a comment


(required, but not displayed)

(optional)