#!/usr/bin/perl

#
# Author: Prabu, SCS, FIU - 2/20/2005
#
# This perl script for DOS -- renames each subdirectory in the current dir
#   that matches a MoodleID of a student
#   to the corresponding student's fullname
#


# Usage:
#  save the following two files in asg folder
#   Mapping.txt (studentMoodleId, Firstname, Lastname -- space separated text file)
#   mvDir.pl (this perl script file)
#
#   download the zip file from moodle for a specific asg (a subfolder of moddata)
#     into asg\n (where n is the asg number)
#   unzip the file (Rightclick -> extract here)
#   cd extracted folder (asg\n\moddatasubfolder)
#  Invoke the script and feed the student-id as
#      type ..\..\Mapping.txt | perl ..\..\mvDir.pl
#

use strict; # import Perl module "strict" -> Perl\lib\strict.pm

# local variable definitions
my $id = "";
my $fname = "";
my $lname = "";
my %map; # hash map associates key (student-id) to value (studentname)

while ( <> ) {
  chomp; # strip the last character
  ($id, $fname, $lname) = split(/ /, $_);
  $map{"$id"} = "\u$fname" . "\u$lname";
}


foreach $id (`dir/b`) {
  $id =~ s/\s*$//; # strip all trailing white spaces
  if (-d $id) {    # if the value of $id is a directory
    if ($map{"$id"} ne "") {
      system("rename $id $map{$id}");
    }
  }
}
