Skip to content

Instantly share code, notes, and snippets.

@milesmatthias
Created October 6, 2014 00:02
Show Gist options
  • Select an option

  • Save milesmatthias/30acbad4b1218a369c65 to your computer and use it in GitHub Desktop.

Select an option

Save milesmatthias/30acbad4b1218a369c65 to your computer and use it in GitHub Desktop.

Revisions

  1. milesmatthias created this gist Oct 6, 2014.
    27 changes: 27 additions & 0 deletions mv_contents_up.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/usr/bin/env ruby

    # for each directory in the current directory:
    #
    # 1. move its contents up one directory (out of its current directory)
    # 2. remove the (now empty) directory
    #
    # ( note: skips hidden files and . and .. )

    require 'pry'
    require 'fileutils'

    Dir.foreach(".") do |entry|
    next if entry.start_with?('.')

    if File.directory?(entry)
    puts "moving contents of #{ entry } up."

    FileUtils.mv Dir.glob(entry + "/*"), "."
    FileUtils.rm_r entry
    end


    end

    exit