Skip to content

Instantly share code, notes, and snippets.

@lp
Created January 12, 2011 16:37
Show Gist options
  • Select an option

  • Save lp/776414 to your computer and use it in GitHub Desktop.

Select an option

Save lp/776414 to your computer and use it in GitHub Desktop.
will rename files to enclosing folder name with sequenced numbers
require 'find'
nowDir = File.dirname( File.expand_path(__FILE__))
nameMem = Hash.new
Find.find( nowDir) do |path|
if ! File.directory?(path)
if File.basename(path).match(/^\..*/).nil?
dirPath = File.dirname(path)
if ! nameMem.has_key? dirPath
nameMem[dirPath] = 0
end
nameMem[dirPath] += 1
File.rename(path,
File.join( dirPath,
sprintf("%s_%03d",
File.basename(dirPath),
nameMem[dirPath])))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment