vss_illegal_filenames.pl #2

  • //
  • guest/
  • robert_cowham/
  • perforce/
  • utils/
  • vss_illegal_filenames.pl
  • View
  • Commits
  • Open Download .zip Download (3 KB)
#!/usr/bin/perl -w
#
# Script to print out VSS files that have "illegal" names as far as Perforce is concerned.
#
# Uses VSS OLE Automation
# Documentation on VSS Object Model can be found at:
# http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvss/html/msdn_vssole.asp
#
# Written by Robert Cowham (rc@vaccaperna.co.uk)
# Usual disclaimers apply!
 
require 5.0;
use strict;
use integer;
use Time::Local;
use Win32::OLE;
use Win32::OLE qw(in);
use Win32::OLE::Const;
use Win32::OLE::Variant;
 
use Getopt::Long;
# Declare the Username, password and SourceSafe path variables
# For now these are hardcoded
my $UserName = "eshare";
my $Password = "";
my $SrcSafeIni = "z:\\SRCSAFE.INI";
my $Verbose;
 
GetOptions ("user=s"   => \$UserName,
                                "password=s" => \$Password,
                                "ssini=s" => \$SrcSafeIni,
                                "verbose" => \$Verbose)
or die("Error in command line arguments\n");
 
my $USAGE = "VSS Path argument required: [vssdir]\ne.g.\n   $0 \"\$/Project 1/subdir\"\n";
my $root = $ARGV[0];
die($USAGE) if !(defined($root));
 
# Load up VSS Ole Automation
my $VSSDB = Win32::OLE->new('SourceSafe', 'Quit');
my $consts = Win32::OLE::Const->Load($VSSDB);
 
 
$VSSDB->Open($SrcSafeIni, $UserName, $Password);
my $VSSRoot = $VSSDB->VSSItem($root, 0);
if (!$VSSRoot) {
                die "Error finding directory \"$root\"\n";
}
print "File names with illegal (for Perforce) chars (@, #, %, * or unprintable chars):\n";
my $count = 0;
my $bad_count = 0;
&vss_dir_tree($root);
print "\n$bad_count illegal files out of $count files in total.\n";
 
# Recurse down the list of VSS directories looking for illegal files (as far as
# Perforce is concerned)
sub vss_dir_tree
{
    my $rt = shift;
 
    my $root = $VSSDB->VSSItem($rt, 0);
    if (!$root) {
        print "Error checking directory: $rt\n";
        return;
    }
 
    print "$root\n" if $Verbose;
   
    my $items = $root->Items(0);
    my $item;
    my $dir;
 
    foreach $item (in $items) {
        if ($item->Type == $consts->{VSSITEM_PROJECT}) {
            $dir = $item->Name;
            &vss_dir_tree("$rt/$dir");
        }
        else {
            &check_file_name("$rt/" . $item->Name);
        }
    }
 
}
 
sub check_file_name
{
    my $file = shift;
 
    $count++;
    print "$file\n" if $Verbose;
    if( $file =~ /[\000-\031\x80-\xFF@#%\*]/ || $file =~ /\.\.\./ ) {
        $bad_count++;
        print "'$file'\n";
    }
}
# Change User Description Committed
#2 12162 Robert Cowham Changed flags.
Changed indent.
Look for more non-printable chars (in range \0x80-\0xff)
#1 3977 Robert Cowham Extra utilities.