Sometimes we need to compare the Source in two directory in VSS, but from the date you can't see anything, you need to compare one by one, and the project is more annoying. So I did a tool that can investigate which files are the same, which is different, which are only in a directory. Compdir.pl #! / usr / bin / perl
DIE "parameter is not enough./N" if @argv <2;
$ now = localtime Time; Print "Compdir Begin AT $ now / N";
SUB Compfile {MY $ file1 = $ _ [0]; my $ file2 = $ _ [1];
Open SRC, "$ file1" or Die "Cannot Open file '$ file1': $! / n"; Open DEST, "$ file2" or die "Cannot Open file '$ file2': $! / n";
My @ Data1 =
Print "<$ file1> and <$ file2> are different files./n" and return if @ data1! = @ data2;
While (1) {MY $ D1 = Shift @ Data1; MY $ D2 = Shift @ Data2; Last IF! Defined $ D1; Print "<$ file1> and <$ file2> are harderent files./n" and returniff $ D1 NE $ D2;} IF (@ Data1! = 0) {Print <$ file1> and <$ file2> area diffrent files./n "and return;
#print "<$ file1> and <$ file2> area same files./n" close src; close dest;}
Sub get_file {my $ dir = $ _ [0]; shift @_; chDIR $ dir or die "Cannot Chdir to '$ dir': $! / n";
MY @files = <*>; foreach $ file (@files) {if (-d "$ dir // $ file") {@_ = & get_file ("$ dir // $ file", @_);} else {Push @_, "$ dir // $ file";}} @_;}
SUB GET_SHORT_NAME {$ String = $ _ [0]; $ mode = $ _ [1];
$ MODE = ~ s /; $ string = ~ s / ^ $ mode;
$ String;}
@ Name1 = & get_file ($ argv [0], @ name1); @ name2 = & get_file ($ argv [1], @ name2);
% NameHash1; foreach (@ name1) {my $ short_name = & get_short_name ($ _, $ ARGV [0]); $ nameHash1 {$ short_name} = $ _;}% nameHash2; foreach (@ name2) {my $ short_name = & get_short_name ($ _, $ Argv [1]); $ namehash2 {$ short_name} = $ _;}
Foreach (@ Name1) {MY $ Short_Name = & GET_SHORT_NAME ($ _, $ Argv [0]); if (exists $ namehash2 {$ limited_name}) {& compfile ($ _, $ namehash2 {$ short_name});} else {print "$ _ exist online! / n";}}
Foreach (@ Name2) {MY $ Short_Name = & Get_Short_Name ($ _, $ Argv [1]); if (exists $ namehash1 {$ limited_name}) {# & compfile ($ _, $ namehash2 {$ short_name});} else { Print "$ _ exist only! / n";}}
$ now = localtime time; Print "compdir end at $ now / n"; Run Results: c: /> perl compdir.pl d: / plsql d: / plsql2compdir begin at Thu Nov 11 17:42:32 2004