organize.rb
# Usage:
#
#   Organize current working directory:
#       ruby organize.rb
#   Specify directory:
#       ruby organize.rb <directory with student files>
#
# Puts all files from one student into a folder with their name.
# Assumes file format used by the "myCourses" service
#
# Matt Mokary (mxm6060@rit.edu)
Organize current working directory:
ruby organize.rb
Specify directory:
ruby organize.rb 

Puts all files from one student into a folder with their name.
Assumes file format used by the "myCourses" service


Organize current working directory : ruby organize . rb Specify directory : ruby organize . rb Puts all files from one student into a folder with their name . Assumes file format used by the " myCourses " service
def main
    filenameRegex = /\d+-\d+ - .+, .+ - .+/
    Dir.chdir( ARGV[0] || "." )
    Dir.foreach(".") do |filename|
        student = filenameRegex.match(filename) ? filename.split(" - ")[1] : ''
        if ( student.include?(", ") )
            if !(File.directory?(student))
                mkdir(student)
            end
            if !(File.directory?(filename))
                mv( filename, student )
            end
        end
    end
end
def main filenameRegex = / \d +- \d + - .+, .+ - .+ / Dir . chdir ( ARGV [ 0 ] || "." ) Dir . foreach ( "." ) do | filename | student = filenameRegex . match ( filename ) ? filename . split ( " - " ) [ 1 ] : '' if ( student . include? ( ", " ) ) if ! ( File . directory? ( student ) ) mkdir ( student ) end if ! ( File . directory? ( filename ) ) mv ( filename , student ) end end end end
Usage:
Organize current working directory:
ruby organize.rb
Specify directory:
ruby organize.rb <directory with student files>
Usage : Organize current working directory : ruby organize . rb Specify directory : ruby organize . rb <directory with student files >
# 12345-1234567 - World, Hello - some-filename.zip