BREAK ON ; IF setconsole("hide") ; ENDIF ; ; NT/95 directories comparison - Kixtart 3.63, 4.00, 4.01, 4.02, 4.10 ; ; (c) scripting@wanadoo.nl - 2001, 2002 ; ; vs 2.00 - program ; ; 1.00 (20010425) original version ; 1.12p (20010501) - production version ; 1.13p (20010510) - make it possible to compare + update specified file(mask) ; by specification of variable $file_mask ; 1.14p (20010701) - minor fix to incorrect substr specification ; 1.15p (20010710) - standardization of $debug_file value ; 1.16p (20011120) - add "windows XP" for calculation of $os value ; 2.00p (20020501) - fix "deltree" problem. previously double SHELL element. ; - add debugging information to screen ; - "deltree" doesn't destroy screen layout. ; add ">nul" part. ; ; external programs (nt4, w2k) "dir /a /b /o:n /s" ; (w95, w98) "dir /a /b /-l /o:n /s" ; (w95, w98) "sort X >Y" ; (nt4) "sort Y" ; (w2k) "sort X /o Y" ; "deltree" ; internal programs copy, del, md ; $prgrm_version="2.00" ; $tmp_directory=ExpandEnvironmentVars("%tmp%") IF (substr($tmp_directory,len($tmp_directory),1) = "\") $tmp_directory=substr($tmp_directory,1,len($tmp_directory)-1) ENDIF $console_file="CON" ; --------------------------------------------------------------------------- ; - site defined settings - ; --------------------------------------------------------------------------- $dir2="X:\fonts" ; - source directory - IF (@inwin = 1) $dir1="c:\winnt\fonts" ; - destination directory - ELSE $dir1="c:\windows\fonts" ; - destination directory - ENDIF $file_mask="*.fon" ; - "" = all files / "*.kix" = only kixtart files - ; $file_mask="*.ttf" ; - "" = all files / "*.kix" = only kixtart files - ; $execute_mode="yes" ; - yes/no - $execute_file=$tmp_directory+"\cmd.kix" ; $debug_mode="yes" ; - yes/no - $debug_file=$tmp_directory+"\kix-info.log" ; --------------------------------------------------------------------------- ; - - ; --------------------------------------------------------------------------- $time_start=@time ; $cr=CHR(10) $lf=CHR(13) $eol=$lf+$cr $eof="~~~ The command completed succesfully ~~~" ; $append_to_redirectoutput=0 $overwrite_to_redirectoutput=1 IF (exist($debug_file) = 1) del $debug_file ENDIF IF (exist($execute_file) = 1) del $execute_file ENDIF ; $os="" $os_dos=@dos SELECT CASE ($NT_mode = "yes") AND ($os_dos = "5.1") ; - Windows XP - $os="XP" CASE ($NT_mode = "yes") AND ($os_dos = "5.0") ; - Windows 2000 - $os="W2K" CASE ($NT_mode = "yes") ; - Windows NT - $os="NT4" CASE ($NT_mode <> "yes") AND ($os_dos = "4.90") ; - Windows ME - $os="ME" CASE ($NT_mode <> "yes") AND ($os_dos = "4.10") ; - Windows 98 - $os="W98" CASE ($NT_mode <> "yes") AND ($os_dos = "4.0") ; - Windows 95 - $os="W95" CASE 1 $os="???" ; - undetermined - ENDSELECT ; -------------------------------------------------------------------------- ; - - ; -------------------------------------------------------------------------- IF (substr($dir1,len($dir1),1) <> "\") $key1=$dir1 $dir1=$dir1+"\" ELSE $key1=substr($dir1,1,len($dir1)-1) ENDIF IF (substr($dir2,len($dir2),1) <> "\") $key2=$dir2 $dir2=$dir2+"\" ELSE $key2=substr($dir2,1,len($dir2)-1) ENDIF IF (RedirectOutput($console_file) = 0) ENDIF IF ($debug_mode = "yes") ? "KIX-DirCompare: DEVELOPMENT ("+$os+" - kixtart "+@kix+" vs "+$prgrm_version+")" ? "KIX-DirCompare: '"+LCASE($dir2)+$file_mask+"' => '"+LCASE($dir1)+$file_mask+"'" ? ELSE ? "KIX-DirCompare: '"+LCASE($dir2)+$file_mask+"' => '"+LCASE($dir1)+$file_mask+"'" ? ENDIF flushkb ; -------------------------------------------------------------------------- ; - special variables settings - ; -------------------------------------------------------------------------- ; - check source + destination directory - $error_message="" IF (exist($key1) <> 1) md $key1 IF (@error = 0) ENDIF IF (exist($key1) <> 1) $error_message="Abort KIX-DirCompare: destination directory '"+$key1+"' doesn't exist." GOSUB show_error_message ENDIF ELSE IF (GetFileAttr($key1) & 16) ELSE ; (= file) $error_message="Abort KIX-DirCompare: destination directory '"+$key1+"' is a file." GOSUB show_error_message ENDIF ENDIF ; IF (exist($key2) <> 1) $error_message="Abort KIX-DirCompare: source directory '"+$key2+"' doesn't exist." GOSUB show_error_message ELSE IF (GetFileAttr($key2) & 16) ELSE ; (= file) $error_message="Abort KIX-DirCompare: source directory '"+$key2+"' is a file." GOSUB show_error_message ENDIF ENDIF IF (len($error_message) <> 0) EXIT ENDIF ; IF ($debug_mode = "yes") IF (RedirectOutput($debug_file,$overwrite_to_redirectoutput) = 0) ENDIF ENDIF ; IF ($debug_mode = "yes") ? "KIX-DirCompare "+@kix+" - "+$os+" debug mode (vs "+$prgrm_version+")"+" "+@time ? ? "mode (execute) "+$execute_mode ? "file (execute) "+$execute_file ? ? "debug_mode "+$debug_mode ? "debug_file "+$debug_file ? ? "source dir. "+LCASE($dir2)+$file_mask+" (dir2)" ? "destination.dir. "+LCASE($dir1)+$file_mask+" (dir1)" ? ENDIF ; -------------------------------------------------------------------------- ; - - ; -------------------------------------------------------------------------- IF (exist($tmp_directory+"\kix-dir1.txt") = 1) del $tmp_directory+"\kix-dir1.txt" ENDIF IF (exist($tmp_directory+"\kix-dir2.txt") = 1) del $tmp_directory+"\kix-dir2.txt" ENDIF del $tmp_directory+"\zzzzz.tmp" SELECT CASE ($os = "W95") OR ($os = "W98") shell "%comspec% /c dir "+CHR(34)+$dir1+$file_mask+CHR(34)+" /a /b /-l /o:n /s >"+$tmp_directory+"\zzzzz.tmp" shell "%comspec% /c sort "+$tmp_directory+"\zzzzz.tmp >"+$tmp_directory+"\kix-dir1.txt" CASE ($os = "NT4") shell "%comspec% /c dir "+CHR(34)+$dir1+$file_mask+CHR(34)+" /a /b /o:n /s >"+$tmp_directory+"\zzzzz.tmp" shell "%comspec% /c sort <"+$tmp_directory+"\zzzzz.tmp >"+$tmp_directory+"\kix-dir1.txt" CASE ($os = "W2K") shell "%comspec% /c dir "+CHR(34)+$dir1+$file_mask+CHR(34)+" /a /b /o:n /s >"+$tmp_directory+"\zzzzz.tmp" shell "%comspec% /c sort "+$tmp_directory+"\zzzzz.tmp /o "+$tmp_directory+"\kix-dir1.txt" CASE 1 shell "%comspec% /c dir "+CHR(34)+$dir1+$file_mask+CHR(34)+" /a /b /o:n /s >"+$tmp_directory+"\kix-dir1.txt" ENDSELECT del $tmp_directory+"\zzzzz.tmp" SELECT CASE ($os = "W95") OR ($os = "W98") shell "%comspec% /c dir "+CHR(34)+$dir2+$file_mask+CHR(34)+" /a /b /-l /o:n /s >"+$tmp_directory+"\zzzzz.tmp" shell "%comspec% /c sort "+$tmp_directory+"\zzzzz.tmp >"+$tmp_directory+"\kix-dir2.txt" CASE ($os = "NT4") shell "%comspec% /c dir "+CHR(34)+$dir2+$file_mask+CHR(34)+" /a /b /o:n /s >"+$tmp_directory+"\zzzzz.tmp" shell "%comspec% /c sort <"+$tmp_directory+"\zzzzz.tmp >"+$tmp_directory+"\kix-dir2.txt" CASE ($os = "W2K") shell "%comspec% /c dir "+CHR(34)+$dir2+$file_mask+CHR(34)+" /a /b /o:n /s >"+$tmp_directory+"\zzzzz.tmp" shell "%comspec% /c sort "+$tmp_directory+"\zzzzz.tmp /o "+$tmp_directory+"\kix-dir2.txt" CASE 1 shell "%comspec% /c dir "+CHR(34)+$dir2+$file_mask+CHR(34)+" /a /b /o:n /s >"+$tmp_directory+"\kix-dir2.txt" ENDSELECT del $tmp_directory+"\zzzzz.tmp" shell "%comspec% /c echo "+$eof+" >>"+$tmp_directory+"\kix-dir1.txt" shell "%comspec% /c echo "+$eof+" >>"+$tmp_directory+"\kix-dir2.txt" $count1=0 $count2=0 $files_equal=0 $files_add=0 $files_del=0 $files_rep=0 $number_of_directories=0 $number_of_files=0 IF (exist($tmp_directory+"\kix-dir1.txt") = 1) AND (exist($tmp_directory+"\kix-dir2.txt") = 1) GOSUB open_file1 GOSUB open_file2 GOSUB open_file9 ; GOSUB readline1 GOSUB readline2 ; $completed="yes" DO $cmd="" $info="" IF ($debug_mode = "yes") GOSUB debug_info1 GOSUB debug_info2 ENDIF IF ($y11 = $y22) GOSUB compare_entries IF ($same_file = "yes") GOSUB command_equal ELSE GOSUB command_rep ENDIF GOSUB readline1 GOSUB readline2 ELSE IF ($y11 < $y22) GOSUB command_del GOSUB readline1 ELSE IF ($y11 > $y22) GOSUB command_add GOSUB readline2 ENDIF ENDIF ENDIF IF ($debug_mode = "yes") ? "=============" ENDIF UNTIL ($completed = "yes") ; IF (INSTR($y1,$eof) <> 0) AND (INSTR($y2,$eof) = 0) DO $cmd="" $info="" IF ($debug_mode = "yes") GOSUB debug_info2 ENDIF GOSUB command_add GOSUB readline2 UNTIL ($completed="yes") ENDIF IF (INSTR($y1,$eof) = 0) AND (INSTR($y2,$eof) <> 0) DO $cmd="" $info="" IF ($debug_mode = "yes") GOSUB debug_info1 ENDIF GOSUB command_del GOSUB readline1 UNTIL ($completed="yes") ENDIF GOSUB close_file1 GOSUB close_file2 GOSUB close_file9 ENDIF IF (exist($tmp_directory+"\kix-dir1.txt") = 1) del $tmp_directory+"\kix-dir1.txt" ENDIF IF (exist($tmp_directory+"\kix-dir2.txt") = 1) del $tmp_directory+"\kix-dir2.txt" ENDIF GOTO end_script ; -------------------------------------------------------------------------- ; - - ; -------------------------------------------------------------------------- :open_file1 $error=open(1, $tmp_directory+"\kix-dir1.txt", 2) IF (@error <> 0) ? "Open '"+$tmp_directory+"\kix-dir1.txt': "+@error+" "+@serror ENDIF RETURN :open_file2 $error=open(2, $tmp_directory+"\kix-dir2.txt", 2) IF (@error <> 0) ? "Open '"+$tmp_directory+"\kix-dir2.txt': "+@error+" "+@serror ENDIF RETURN :open_file9 $error=open(9, $execute_file, 5) IF (@error <> 0) ? "Open '"+$execute_file+"': "+@error+" "+@serror ENDIF IF ($execute_mode <> "yes") IF writeline(9, 'IF setconsole("hide")'+$eol) ENDIF IF writeline(9, 'ENDIF'+$eol) ENDIF IF writeline(9, '? "KIX-DirCompare: '+"'"+LCASE($dir2+$file_mask)+"' -> '"+LCASE($dir1+$file_mask)+"'"+'"'+$eol) ENDIF IF writeline(9, '?'+$eol) ENDIF ENDIF RETURN :close_file1 IF close (1) ENDIF RETURN :close_file2 IF close (2) ENDIF RETURN :close_file9 IF writeline(9, '?'+$eol) ENDIF IF writeline(9, '? "completed"'+$eol) ENDIF IF close (9) ENDIF IF ($execute_mode = "yes") IF (exist($execute_file) = 1) del $execute_file ENDIF ENDIF RETURN :show_error_message ? $error_message RETURN :readline1 $y1=readline (1) $y1=LTRIM(RTRIM($y1)) IF (@error = 0) $completed="no" ELSE $completed="yes" ENDIF IF (INSTR($y1,$eof) <> 0) $completed="yes" ENDIF $y11=$y1 IF ($completed <> "yes") AND (len($y1) > len($dir1)) $y11=substr($y1,len($dir1)+1,len($y1)-len($dir1)) ENDIF IF (GetFileAttr($y1) & 16) $file_type1="d" ELSE $file_type1="f" ENDIF $count1=$count1+1 RETURN :readline2 $y2=readline (2) $y2=LTRIM(RTRIM($y2)) IF (@error = 0) $completed="no" ELSE $completed="yes" ENDIF IF (INSTR($y2,$eof) <> 0) $completed="yes" ENDIF $y22=$y2 IF ($completed <> "yes") AND (len($y2) > len($dir2)) $y22=substr($y2,len($dir2)+1,len($y2)-len($dir2)) ENDIF IF (GetFileAttr($y2) & 16) $number_of_directories=$number_of_directories+1 $file_type2="d" ELSE $number_of_files=$number_of_files+1 $file_type2="f" ENDIF ; IF ($file_type2 = "d") IF ($debug_mode = "yes") IF (RedirectOutput($console_file) = 0) ENDIF ? "[d] " Substr(" ",1,5-len("$files_add")) $files_add "a" Substr(" ",1,5-len("$files_del")) $files_del "d" Substr(" ",1,5-len("$files_rep")) $files_rep "r" Substr(" ",1,5-len("$files_equal")) $files_equal "=" " "+$y2 IF (RedirectOutput($debug_file,$append_to_redirectoutput) = 0) ENDIF ELSE ? "[d] "+$y2 ENDIF ELSE IF ($debug_mode = "yes") ; IF (RedirectOutput($console_file) = 0) ; ENDIF ; ? "[f] "+$y2 ; IF (RedirectOutput($debug_file,$append_to_redirectoutput) = 0) ; ENDIF ELSE ; ? "[f] "+$y2 ENDIF ENDIF $count2=$count2+1 RETURN ; -------------------------------------------------------------------------- ; - - ; -------------------------------------------------------------------------- :compare_entries $same_file="yes" IF ($file_type1 <> $file_type2) IF ($file_type1 = "d") IF ($file_type2 <> "d") ; (= file) gosub command_del ; - del file/directory before create directory/copy file $same_file="no" ENDIF ELSE IF ($file_type2 = "d") gosub command_del ; - del file/directory before create directory/copy file $same_file="no" ENDIF ENDIF ENDIF IF (GetFileSize($y1) <> GetFileSize($y2)) $same_file="no" ENDIF IF (GetFileTime($y1) <> GetFileTime($y2)) $same_file="no" ENDIF ; IF (GetFileTime($y1) > GetFileTime($y2)) $info="-INFO- file '"+$y1+"' newer. no update" GOSUB command_logging $same_file="yes" ENDIF RETURN :command_add $files_add=$files_add+1 IF ($file_type2 = "d") IF ($execute_mode = "yes") md $dir1+$y22 ELSE $cmd="md "+CHR(34)+$dir1+$y22+CHR(34) ENDIF $info= "md "+CHR(34)+$dir1+$y22+CHR(34) ELSE IF (exist($dir1+$y22) = 1) IF (SetFileAttr($dir1+$y22, 32) = 0) ENDIF ENDIF IF ($execute_mode = "yes") copy $y2 $dir1+$y22 /H ELSE $cmd="copy "+CHR(34)+$y2+CHR(34)+" "+CHR(34)+$dir1+$y22+CHR(34)+" /H" ENDIF $info= "copy "+CHR(34)+$y2+CHR(34)+" "+CHR(34)+$dir1+$y22+CHR(34) ENDIF GOSUB command_logging GOSUB command_execution RETURN :command_del $cmd="" $files_del=$files_del+1 IF (exist($y1) = 1) IF ($file_type1 = "d") $cmd="deltree /y "+CHR(34)+$y1+CHR(34) $info="shell '%comspec% /c "+$cmd+"'" ELSE IF (SetFileAttr($y1, 32) = 0) ENDIF IF ($execute_mode = "yes") del $y1 ELSE $cmd="del "+CHR(34)+$y1+CHR(34) ENDIF $info= "del "+CHR(34)+$y1+CHR(34) ENDIF GOSUB command_logging GOSUB command_execution ENDIF RETURN :command_rep $cmd="" $files_rep=$files_rep+1 IF ($file_type2 = "d") $info="-INFO- directory '"+$y2+"' can't be copied." ELSE IF (SetFileAttr($dir1+$y22, 32) = 0) ENDIF IF ($execute_mode = "yes") copy $y2 $dir1+$y22 /H ELSE $cmd="copy "+CHR(34)+$y2+CHR(34)+" "+CHR(34)+$dir1+$y22+CHR(34)+" /H" ENDIF $info= "copy "+CHR(34)+$y2+CHR(34)+" "+CHR(34)+$dir1+$y22+CHR(34) ENDIF GOSUB command_logging GOSUB command_execution RETURN :command_equal $files_equal=$files_equal+1 $cmd="; =equal= '"+$y1+"'" $info=$cmd ;GOSUB command_logging ;GOSUB command_execution RETURN :command_logging IF (len($info) <> 0) IF ($debug_mode = "yes") IF ($file_type2 = "d") ? $info+" (directory)" ELSE ? $info ENDIF ENDIF ENDIF $info="" RETURN :command_execution IF (len($cmd) <> 0) IF ($execute_mode = "yes") shell "%comspec% /c "+$cmd+" >nul" ELSE IF ($debug_mode = "yes") SELECT CASE (instr(LCASE($cmd),"copy ") = 1) ; (= use $file_type2) ; IF writeline(9, "? '[f] "+$cmd+"'"+$eol) ; ENDIF CASE (instr(LCASE($cmd),"del ") = 1) ; (= use $file_type1) ; IF writeline(9, "? '[f] "+$cmd+"'"+$eol) ; ENDIF CASE (instr(LCASE($cmd),"md ") = 1) ; (= use $file_type2) IF writeline(9, "? '[d] "+$cmd+"'"+$eol) ENDIF CASE (instr(LCASE($cmd),"shell") = 1) ; (= use $file_type1) IF (instr(LCASE($cmd),"deltree") <> 0) IF writeline(9, "? '[d] shell - deltree'"+$eol) ENDIF ELSE IF writeline(9, "? '[d] shell'"+$eol) ENDIF ENDIF ENDSELECT ENDIF IF writeline(9, $cmd+$eol) ENDIF ENDIF ENDIF $cmd="" RETURN :debug_info1 $attr="" IF GetFileAttr($y1) & 1 ; - readonly - $attr=$attr+"r" ELSE $attr=$attr+"." ENDIF IF GetFileAttr($y1) & 2 ; - hidden - $attr=$attr+"h" ELSE $attr=$attr+"." ENDIF IF GetFileAttr($y1) & 4 ; - system - $attr=$attr+"s" ELSE $attr=$attr+"." ENDIF IF GetFileAttr($y1) & 16 ; - directory - $attr=$attr+"d" ELSE $attr=$attr+"." ENDIF IF GetFileAttr($y1) & 32 ; - archive - $attr=$attr+"a" ELSE $attr=$attr+"." ENDIF $attr=$attr+" " ? 10000+$count1 " read 1 " $attr 10000+len($y1) " "+GetFileTime($y1)+" "+$y1 ? 10000+$count1 " read 1 " $attr 10000+len($y11) " "+GetFileTime($y1)+" "+$y11+" <- "+$dir1+$file_mask+" ("+GetFileSize($y1)+"B "+GetFileAttr($y1)+")" RETURN :debug_info2 $attr="" IF GetFileAttr($y2) & 1 ; - readonly - $attr=$attr+"r" ELSE $attr=$attr+"." ENDIF IF GetFileAttr($y2) & 2 ; - hidden - $attr=$attr+"h" ELSE $attr=$attr+"." ENDIF IF GetFileAttr($y2) & 4 ; - system - $attr=$attr+"s" ELSE $attr=$attr+"." ENDIF IF GetFileAttr($y2) & 16 ; - directory - $attr=$attr+"d" ELSE $attr=$attr+"." ENDIF IF GetFileAttr($y2) & 32 ; - archive - $attr=$attr+"a" ELSE $attr=$attr+"." ENDIF $attr=$attr+" " ? 10000+$count2 " read 2 " $attr 10000+len($y2) " "+GetFileTime($y2)+" "+$y2 ? 10000+$count2 " read 2 " $attr 10000+len($y22) " "+GetFileTime($y2)+" "+$y22+" <- "+$dir2+$file_mask+" ("+GetFileSize($y2)+"B "+GetFileAttr($y2)+")" RETURN :summary_info ? IF ($count2 > 0) ? $count2 - 1 " lines read from '"+LCASE($dir2+$file_mask)+"' (source directory)" ENDIF IF ($count1 > 0) ? $count1 - 1 " lines read from '"+LCASE($dir1+$file_mask)+"' (destination directory)" ENDIF ? ? "equal "+$files_equal ? "add "+$files_add ? "del "+$files_del ? "rep "+$files_rep ? ? "#files " $number_of_files-1 ? "#dirs " $number_of_directories ? ? "elapse time "+$time_start+" - "+$time_stop+" (kixtart "+@kix+" vs "+$prgrm_version+")" ? "completed" ? RETURN :short_info ? $number_of_directories " dirs + " $number_of_files " files " "(add " $files_add " del " $files_del " rep " $files_rep ")" RETURN ; -------------------------------------------------------------------------- ; - end - ; -------------------------------------------------------------------------- :end_script $time_stop=@time IF ($debug_mode = "yes") cls GOSUB summary_info IF (RedirectOutput($console_file) = 0) ENDIF ENDIF IF (RedirectOutput($console_file) = 0) ENDIF flushkb ; ? IF ($execute_mode = "yes") ? "Informative DirCompare.KIX: direct execution of commands" ELSE ? "Informative DirCompare.KIX: create execution file '"+$execute_file+"'" ENDIF IF ($debug_mode = "yes") ? "Informative DirCompare.KIX: create debug list '"+$debug_file+"'" ELSE ? "Informative DirCompare.KIX: no creation of debug list '"+$debug_file+"'" ENDIF IF ($debug_mode = "yes") GOSUB summary_info ELSE GOSUB short_info ENDIF