本帖最后由 zcx880517 于 2012-4-1 22:04 编辑
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
$FORM = GUICREATE( "文件对比工具" , 230 , 130 )
GUICTRLCREATELABEL( "目录1:" , 15 , 15 , 45 , 18 )
$INPUT1 = GUICTRLCREATEINPUT( "" , 60 , 15 , 125 , 18 )
$BUTTON1 = GUICTRLCREATEBUTTON( "浏览" , 185 , 15 , 30 , 18 )
GUICTRLCREATELABEL( "目录2:" , 15 , 45 , 45 , 18 )
$INPUT2 = GUICTRLCREATEINPUT( "" , 60 , 45 , 125 , 18 )
$BUTTON2 = GUICTRLCREATEBUTTON( "浏览" , 185 , 45 , 30 , 18 )
GUICTRLCREATELABEL( "紧比对:" , 15 , 75 , 50 , 18 )
$RADIO1 = GUICTRLCREATERADIO( "全部" , 65 , 75 , 45 , 18 )
GUICTRLSETSTATE( $RADIO1 , $GUI_CHECKED )
$RADIO2 = GUICTRLCREATERADIO( "目录" , 118 , 75 , 45 , 18 )
$RADIO3 = GUICTRLCREATERADIO( "文件" , 170 , 75 , 45 , 18 )
$CHECKBOX = GUICTRLCREATECHECKBOX( "应用到所有子目录" , 25 , 105 , 130 , 18 )
$OK = GUICTRLCREATEBUTTON( "OK" , 155 , 105 , 50 , 18 )
GUISETSTATE( @SW_SHOW )
WHILE 1
SWITCH GUIGETMSG( )
CASE $BUTTON1
$PATH1 = FILESELECTFOLDER( "选择目录(1)" , "" , 2 )
IF @ERROR <> 1 THEN GUICTRLSETDATA( $INPUT1 , $PATH1 )
CASE $BUTTON2
$PATH2 = FILESELECTFOLDER( "选择目录(2)" , "" , 2 )
IF @ERROR <> 1 THEN GUICTRLSETDATA( $INPUT2 , $PATH2 )
CASE $OK
IF GUICTRLREAD( $INPUT1 ) <> "" AND GUICTRLREAD( $INPUT2 ) <> "" THEN
WINSETSTATE( $FORM , "" , @SW_HIDE )
TOOLTIP( @CR & "程序正在比对文件" & @CR , @DESKTOPWIDTH - 260 , @DESKTOPHEIGHT - 120 )
LOCAL $REPORT = FILEOPEN( "Report.txt" , 2 )
_CMP ( GUICTRLREAD( $INPUT1 ) , GUICTRLREAD( $INPUT2 ) )
_CMP ( GUICTRLREAD( $INPUT2 ) , GUICTRLREAD( $INPUT1 ) )
FILECLOSE( $REPORT )
MSGBOX( 0 , "ok" , "全部文件已比对完成。")
RUN( "Notepad Report.txt" )
EXIT
ELSE
MSGBOX( 0 + 48 , "提示" , "比对目录不能为空!" )
ENDIF
CASE $GUI_EVENT_CLOSE
EXIT
ENDSWITCH
WEND
FUNC _CMP ( $DIR1 = "" , $DIR2 = "" )
IF STRINGRIGHT( $DIR1 , 1 ) <> "\" THEN $DIR1 &= "\"
IF STRINGRIGHT( $DIR2 , 1 ) <> "\" THEN $DIR2 &= "\"
LOCAL $FOLEXISTNUM = 0 , $FILEXISTNUM = 0 , $FOLEXISTNAME = "" , $FILEXISTNAME = ""
LOCAL $FOLNOTEXISTNUM = 0 , $FILNOTEXISTNUM = 0 , $FOLNOTEXISTNAME = "" , $FILNOTEXISTNAME = ""
LOCAL $SEARCH , $FILE
$SEARCH = FILEFINDFIRSTFILE( $DIR1 & "*.*" )
WHILE 1
$FILE = FILEFINDNEXTFILE( $SEARCH )
IF @ERROR THEN EXITLOOP
IF GUICTRLREAD( $CHECKBOX ) = $GUI_CHECKED THEN
IF STRINGINSTR( FILEGETATTRIB( $DIR1 & $FILE ) , "D" ) THEN _CMP ( $DIR1 & $FILE , $DIR2 & $FILE )
ENDIF
IF FILEEXISTS( $DIR2 & $FILE ) THEN
IF STRINGINSTR( FILEGETATTRIB( $DIR2 & $FILE ) , "D" ) THEN
IF GUICTRLREAD( $RADIO1 ) = $GUI_CHECKED OR GUICTRLREAD( $RADIO2 ) = $GUI_CHECKED THEN
$FOLEXISTNUM += 1
$FOLEXISTNAME &= $FILE & @CRLF
ENDIF
ELSE
IF GUICTRLREAD( $RADIO1 ) = $GUI_CHECKED OR GUICTRLREAD( $RADIO3 ) = $GUI_CHECKED THEN
$FILEXISTNUM += 1
$FILEXISTNAME &= $FILE & @CRLF
ENDIF
ENDIF
ELSE
IF STRINGINSTR( FILEGETATTRIB( $DIR1 & $FILE ) , "D" ) THEN
IF GUICTRLREAD( $RADIO1 ) = $GUI_CHECKED OR GUICTRLREAD( $RADIO2 ) = $GUI_CHECKED THEN
$FOLNOTEXISTNUM += 1
$FOLNOTEXISTNAME &= $FILE & @CRLF
ENDIF
ELSE
IF GUICTRLREAD( $RADIO1 ) = $GUI_CHECKED OR GUICTRLREAD( $RADIO3 ) = $GUI_CHECKED THEN
$FILNOTEXISTNUM += 1
$FILNOTEXISTNAME &= $FILE & @CRLF
ENDIF
ENDIF
ENDIF
WEND
FILECLOSE( $SEARCH )
FILEWRITELINE( $REPORT , @CRLF & $DIR1 & @CRLF & @CRLF )
IF GUICTRLREAD( $RADIO1 ) = $GUI_CHECKED OR GUICTRLREAD( $RADIO2 ) = $GUI_CHECKED THEN
FILEWRITELINE( $REPORT , " 相同目录数: " & $FOLEXISTNUM & " 多出目录数: " & $FOLNOTEXISTNUM )
ENDIF
IF GUICTRLREAD( $RADIO1 ) = $GUI_CHECKED OR GUICTRLREAD( $RADIO3 ) = $GUI_CHECKED THEN
FILEWRITELINE( $REPORT , " 相同文件数: " & $FILEXISTNUM & " 多出文件数: " & $FILNOTEXISTNUM )
ENDIF
FILEWRITELINE( $REPORT , @CRLF )
IF GUICTRLREAD( $RADIO1 ) = $GUI_CHECKED OR GUICTRLREAD( $RADIO2 ) = $GUI_CHECKED THEN
IF $FOLEXISTNUM > 0 THEN FILEWRITELINE( $REPORT , " 相同目录列表:" & @CRLF & $FOLEXISTNAME & @CRLF )
IF $FOLNOTEXISTNUM > 0 THEN FILEWRITELINE( $REPORT , " 多出目录列表:" & @CRLF & $FOLNOTEXISTNAME & @CRLF )
ENDIF
IF GUICTRLREAD( $RADIO1 ) = $GUI_CHECKED OR GUICTRLREAD( $RADIO3 ) = $GUI_CHECKED THEN
IF $FILEXISTNUM > 0 THEN FILEWRITELINE( $REPORT , " 相同文件列表:" & @CRLF & $FILEXISTNAME & @CRLF )
IF $FILNOTEXISTNUM > 0 THEN FILEWRITELINE( $REPORT , " 多出文件列表:" & @CRLF & $FILNOTEXISTNAME & @CRLF )
ENDIF
ENDFUNC
|