home *** CD-ROM | disk | FTP | other *** search
- @rem = '-*- Perl -*-';
- @rem = '
- @echo off
- perl %0.cmd %1 %2 %3 %4 %5 %6 %7 %8 %9
- goto endofperl
- ';
-
- require 'ntfind.pl';
- require 'getopts.pl';
-
- &Getopts('i');
-
- @badmsg = @badfiles = ();
-
- #
- # find all the files that don't fit the stupid 8.3 filename rules
- #
-
- foreach $dir (@ARGV) {
- &find($dir) if -d $dir;
- }
-
- #
- # Now print them out
- #
-
- while(@badfiles > 0) {
- $file = pop (@badfiles);
- $msg = pop (@badmsg);
- if ($opt_i) {
- &do_rename($file, $msg);
- }
- else {
- print "$file : $msg\n";
- }
- }
-
- sub wanted {
- local ($msg);
- if ($msg = &checkname($_)) {
- push(@badfiles, $name);
- push(@badmsg, $msg);
- }
- }
-
- sub checkname {
- local(@parts) = split (/\./, $_[0]);
- local($checkmsg) = "";
-
- if ($#parts > 2) {
- $checkmsg = "too many dots";
- }
- elsif (length($parts[0]) > 8) {
- $checkmsg = "name greater than 8 characters";
- }
- elsif (length($parts[1]) > 3) {
- $checkmsg = "extension greater than 3 characters";
- }
- $checkmsg;
- }
-
- sub do_rename {
- local($path, $msg) = @_;
- local($valid_name) = 0;
- local($newname);
-
- #
- # Tell the user what's wrong with the file, then prompt
- # for a new name. Make sure that the new name doesn't exist,
- # and that it's a legal 8.3 name. Then do the rename.
- #
-
- $path =~ s|/|\\|g;
-
- do {
- print "$msg\nRename $path to: ";
- $newname = &gets;
- if (-e $newname) {
- print STDERR "Can't rename $file to $newname (file exists)\n";
- redo;
- }
- split(m;[/\\];, $newname);
- if (($msg = &checkname($_[$#_])) == ""){
- rename($path, $newname) && ($valid_name = 1);
- warn "rename of $path to $newname failed: $!\n"
- if $valid_name == 0;
- }
- } while (! $valid_name);
-
- #
- # Now log the old and new names
- #
-
- open(M, ">>rename.map")
- || warn "Can't open rename.map for append: $!\n" && return;
- print M "$file -> $newname\n";
- close M;
- }
-
- sub gets {
- local ($c);
- local (@string) = ();
-
- while(($c = getc) ne "\n") {
- push(@string, $c);
- }
- join (//, @string);
- }
-
-
-
- __END__
- :endofperl
-