module DsUtils
Constants
- VERSION
Public Class Methods
create_do_file()
click to toggle source
# File lib/ds_utils.rb, line 26 def self.create_do_file @do_file = "flatten_directory_#{timestamp}.rb" File.open(@do_file, 'w', 0744) {|file| file.puts "#!/usr/bin/env ruby" @move_files.each {|ll| file.puts "File.rename '#{ll}', '#{move_to_name(ll)}'" } @subdirectories.sort{|a,b| b.count(File::SEPARATOR) - a.count(File::SEPARATOR)}.each {|sd| file.puts "Dir.rmdir('#{sd}')" } } end
create_undo_file()
click to toggle source
# File lib/ds_utils.rb, line 41 def self.create_undo_file @undo_file = "unflatten_directory_#{timestamp}.rb" File.open(@undo_file, 'w', 0744) {|file| file.puts "#!/usr/bin/env ruby" file.puts "require 'fileutils'" @subdirectories.each {|sd| file.puts "FileUtils.mkdir_p '#{sd}' unless Dir.exist?('#{sd}')" } @move_files.each {|ll| file.puts "File.rename '#{move_to_name(ll)}', '#{ll}'" } } end
flatten(thisdir)
click to toggle source
Move tiles from subdirectories of topdir to topdir
# File lib/ds_utils.rb, line 5 def self.flatten(thisdir) @do_listing = [] @undo_listing = [] @move_files = [] dir_contents = Dir["#{thisdir}/**/*"] @move_files = dir_contents.reject{|item| File.directory?(item)} @subdirectories = dir_contents.select{|item| File.directory?(item)} create_do_file create_undo_file puts "Please examine the contents of file #{@do_file} and then execute it with the command:" puts " ./#{@do_file}" puts "To undo the changes, please execute:" puts " ./#{@undo_file}" return [@do_file, @undo_file] end
move_to_name(filename)
click to toggle source
# File lib/ds_utils.rb, line 56 def self.move_to_name(filename) split_string_array = filename.split(File::SEPARATOR) return split_string_array[0] + File::SEPARATOR + split_string_array[1..-1].join('_') end
timestamp()
click to toggle source
# File lib/ds_utils.rb, line 61 def self.timestamp return Time.now.strftime("%Y_%m_%d_%Y%m%dT%H%M%S%z") end