#!/usr/bin/perl -w # # Script to print out "deleted" files in VSS # # 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; 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 Win32::OLE->Option(Warn => 0); # No warnings my $VSSDB = Win32::OLE->new('SourceSafe', 'Quit'); my $consts = Win32::OLE::Const->Load($VSSDB); # Declare the Username, password and SourceSafe path variables # For now these are hardcoded my $UserName = "eshare"; my $Password = ""; my $SrcSafeIni = "z:\\SRCSAFE.INI"; $VSSDB->Open($SrcSafeIni, $UserName, $Password); my $VSSRoot = $VSSDB->VSSItem($root, 0); if (!$VSSRoot) { die "Error finding directory \"$root\"\n"; } print "Deleted VSS files in '$root':\n"; my $count = 0; my $deleted_count = 0; my $deleted_dirs_count = 0; &vss_dir_tree($root); print "\n$deleted_count deleted files out of $count files in total.\n"; print "$deleted_dirs_count deleted directories.\n"; # Recurse down the list of VSS directories looking for deleted files sub vss_dir_tree { my $rt = shift; my $root = $VSSDB->VSSItem($rt, 1); if ($root) { $deleted_dirs_count++; print "'$rt'\n"; } else { $root = $VSSDB->VSSItem($rt, 0); if (!$root) { print "Error checking directory: $rt\n"; return; } } my $items = $root->Items(1); my $item; my $dir; foreach $item (in $items) { if ($item->Type == $consts->{VSSITEM_PROJECT}) { $dir = $item->Name; &vss_dir_tree("$rt/$dir"); } else { &check_deleted("$rt/".$item->Name); } } } sub check_deleted { my $file = shift; $count++; my $item = $VSSDB->VSSItem($file, 1); if (!$item) { return; } if($item->Deleted) { $deleted_count++; print "'$file'\n"; } }