Class: MagicShelf::DirRenamer

Inherits:
Object
  • Object
show all
Defined in:
lib/magicshelf/dirrenamer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#workdirObject

Returns the value of attribute workdir.



7
8
9
# File 'lib/magicshelf/dirrenamer.rb', line 7

def workdir
  @workdir
end

Instance Method Details

#enterObject



8
9
10
# File 'lib/magicshelf/dirrenamer.rb', line 8

def enter()
  yield
end

#processObject



12
13
14
15
# File 'lib/magicshelf/dirrenamer.rb', line 12

def process()
  @workdir ||= Dir.pwd
  rename_dir_recursively(@workdir)
end

#rename_dir_recursively(path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/magicshelf/dirrenamer.rb', line 17

def rename_dir_recursively(path)
    Dir.chdir(path) {
      Dir['./*'].select{|f|File.directory?(f)}.each.with_index { |f,index|
        if File.directory?(f)
          rename_dir_recursively(f)
          FileUtils.mv(f, index.to_s)
        end
      }
    }
end