Here I attach a perl script that renames directory names suitable for grading. I hope it will be of your help. -- Manabu Torii torii@UDel.edu Usage: strauss> perl rename.pl is the CSV file containing students' info, which can be downloaded from the WebCT. (Or, please use the file attached, "class_Mar30.txt") is the directory under which the zip file from the WebCT has been expanded. E.g., > ls CISC181_010_04S_assignments_Apr10.zip class_Mar30.txt rename.pl > mkdir Homework > cd Homework/ > cp ../CISC181_010_04S_assignments_Apr10.zip . > unzip CISC181_010_04S_assignments_Apr10.zip Archive: CISC181_010_04S_assignments_Apr10.zip creating: bbrewer/ creating: alhughes/ inflating: alhughes/lab05p1.txt inflating: alhughes/lab05p2.txt .... > perl ../rename.pl ../class_Mar30.txt . move: ./abach --> ./M15__Bach____________Amanda_______abach_____ move: ./abnelth --> ./M15__Nelthropp_______Aaron________abnelth___ move: ./ac --> ./A16__Rosenzweig______Adam_________ac________ move: ./acabrera --> ./M15__Cabrera_________Alexander____acabrera__ move: ./alhughes --> ./B12__Hughes__________Alex_________alhughes__ ... > --MIMEStream=_0+269883_21616555513785_0093098132 Content-Type: application/DEFANGED-299727; name="rename_pl.DEFANGED-299727" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="rename_pl.DEFANGED-299727" #! /opt/bin/perl # # usage: # > perl rename.pl # # use File::Copy; use strict; # # read "class_MMDD.csv" # # # 1. read the file # open(FIN, $ARGV[0]) || die "error: name file not found"; my @records = ; close(FIN); # # 2. store column names # my $attributes = shift(@records); chomp($attributes); my @attributes = split(/,/,$attributes); # # 3. read and store the remaining info in the name list. # my $lmax; # max length of the last name my $fmax; # max length of the first name my $umax; # max lenght of the user id my $smax; # max length of the section name my %records; # keep students' info # # reach each student' record # foreach my $rec (@records) { chomp($rec); my @fields = split(/,/,$rec); my ($sec, $lname, $fname, $uid) = (undef,undef,undef,undef); # # read each field of the record # for( my $i = 0; $i < scalar @fields; $i++ ) { if( $attributes[$i] eq "Section" ) { $sec = $fields[$i]; } elsif( $attributes[$i] eq "Last Name" ) { $lname = $fields[$i]; $lname =~ s/\s/_/g } elsif( $attributes[$i] eq "First Name" ) { $fname = $fields[$i]; $fname =~ s/\s/_/g } elsif( $attributes[$i] eq "User ID" ) { $uid = $fields[$i]; } } if( ( ! defined $sec || $sec eq "" ) && ( ! defined $lname || $lname eq "" ) && ( ! defined $fname || $fname eq "" ) && ( ! defined $uid || $uid eq "" ) ) { next } elsif( ! defined $sec || $sec eq "" ) { $sec = "X"; } $lmax = length($lname) if( $lmax < length($lname) ); $fmax = length($fname) if( $fmax < length($fname) ); $umax = length($uid) if( $umax < length($uid) ); $smax = length($sec) if( $smax < length($sec) ); ${$records{$uid}}{"sec"} = $sec; ${$records{$uid}}{"lname"} = $lname; ${$records{$uid}}{"fname"} = $fname; # printf("%s %s, %s\n", $sec, $lname, $fname); } # # 4. rename directory from user name to the real name # # insert gaps between last name, first name, or user id. $lmax += 2; $fmax += 2; $umax += 2; $smax += 2; # my $path = $ARGV[1] . "/"; $path =~ s/\/\/$/\//; if( ! -d $path ) { printf(stderr "error: 2nd arg. should be the dir name.\n\n"); exit(1); } foreach my $uid (sort keys %records) { my $sec = ${$records{$uid}}{"sec"}; my $lname = ${$records{$uid}}{"lname"}; my $fname = ${$records{$uid}}{"fname"}; # printf("%3s %s\n", $sec, $uid); if( ! -r $path.$uid ) { printf(stderr "warning: dir not exists \"%s\"\n", $path.$uid); next; } my $newfile; $newfile = sprintf("%s", $sec); for( my $i = length($sec); $i < $smax; $i++ ) { $newfile .= "_"; } $newfile .= sprintf("%s", $lname); for( my $i = length($lname); $i < $lmax; $i++ ) { $newfile .= "_"; } $newfile .= sprintf("%s", $fname); for( my $i = length($fname); $i < $fmax; $i++ ) { $newfile .= "_"; } $newfile .= sprintf("%s", $uid); for( my $i = length($uid); $i < $umax; $i++ ) { $newfile .= "_"; } # # # if( -r $path.$newfile ) { printf("warning: file \"%s\" already exists.\n\n", $path.$newfile); } elsif( move($path.$uid, $path.$newfile) ) { printf("move: %-24s --> %s\n", $path.$uid, $path.$newfile); } else { printf("error: mv %s %s, failed.\n\n", $path.$uid, $path.$newfile); } } --MIMEStream=_0+269883_21616555513785_0093098132 Content-Type: text/plain; name="class_Mar30.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="class_Mar30.txt" Last Name,First Name,User ID,Section --MIMEStream=_0+269883_21616555513785_0093098132--