#! /bin/perl
#############################################################################
#
# NOTE: This file under revision control using RCS
# Any changes made without RCS will be lost
#
# $Source: U:\\mhansen\\bin\\RCS\\ymi2ntfs.pl,v $
# $Revision: 1.0 $
# $Date: 2001-11-08 00:59:07-06 $
# $Author: mhansen $
# $Locker: mhansen $
# $State: Exp $
#
# Purpose: Utility to convert CD-ROM ISO 9960 file names to
# original long file names as stored in YMTRANS.TBL in
# each directory.
#
# This methodology predates the Joliet file system and
# was introduced by Young Minds
# when drivers supporting the Rock Ridge extensions
# were not widely available.
#
# Directions: Usage: ymi2ntfs.pl [directory]
# directory is optional argument, directory to start
# in. Current directory is default.
#
# For compatibility with NTFS filenames, leading periods
# and other invalid characters, \ / : * ? " < > | are
# changed to underscores.
#
# Default Location: U:\mhansen\bin
#
# Invoked by: user
#
# Copyright (C) 2001 Marc Hansen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation available at:
# http://http://www.gnu.org/copyleft/gpl.html
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
#############################################################################
#
#
# REVISION HISTORY:
#
# $Log: ymi2ntfs.pl,v $
# Revision 1.0 2001-11-08 00:59:07-06 mhansen
# Initial revision
#
#
#
#
#
# Constants
#
$YMTABLE = "YMTRANS.TBL"; # YMi name conversion table in each dir
#
# Get starting directory
#
$start = "@ARGV[0]";
if (! $start) {$start = "."}
#
# Main
#
subdir ($start);
exit 0;
###################
#
# Function: subdir
# Purpose: Translate names of each directory and file in directory
# provided as argument. Call self recursively for each
# sub directory found in current dir
#
sub subdir {
my ($path) = @_[0];
my @dirlist;
# Translate contents of this directory
ymtrans ("$path");
# Build list of directories and save so we don't have open
# file handles all over the place from recursion
opendir(DIR, $path);
while (defined($dir = readdir(DIR))) {
if (-d "$path\\$dir" && "$dir" ne "." && "$dir" ne ".." ) {
push @dirlist, "$path\\$dir";
}
}
closedir (DIR);
# Recursively call this method for each dir
foreach $dir (@dirlist) {
print "Found sub directory: $dir\n";
subdir ("$dir");
}
}
###################
#
# Function: ymtrans
# Purpose: See if there is a YMTRANS.TBL file in this directory
# If so, use to rename all files and directories
# Won't hurt to run this more than once
#
sub ymtrans {
my ($path) = @_[0];
print "Translating names in $path\n";
if (-e "$path\\$YMTABLE") {
print "Found $path\\$YMTABLE\n";
open TABLE, "$path\\$YMTABLE";
while (
){
($type, $iso, $long) = split ' ';
($short, $num) = split /;/, "$iso";
$long =~ s/^\./_/;
$long =~ s/[\\ \/ \: \* \? \" \< \> \|]/_/g;
if (-e "$path\\$short" || -d "$path\\$short") {
print "\tRenaming: $path\\$short to $path\\$long \n";
rename("$path\\$short", "$path\\$long") or
warn "\tFailed: $path\\$short to $path\\$long: $!\n";
} else {print "\tNot found: $path\\$short \n";}
}
}
close TABLE
}
__END__