我在删除不要的内容,有一个目录里的内容,很多,我只想保留指定的几个目录和文件把其它的都删除掉,怎么才 ...
zlmyongheng 发表于 2011-10-1 19:26
试试下面的,没有测试过
#Include <File.au3>
#include <Array.au3>
Local $aDir, $aFile, $Dir = "d:\123", $aRetDir[2] = ["ff", "gg"], $aRetFile[2] = ["bb.mms", "55.t66"]
$aDir = _FileListToArray($Dir, "*", 2)
If IsArray($aDir) Then
_ArrayDelete($aDir, 0)
$aDir = CompareArray($aDir, $aRetDir)
For $i = 0 To UBound($aDir) - 1
DirRemove($Dir & "\" & $aDir[$i], 1)
Next
EndIf
$aFile = _FileListToArray($Dir, "*.*", 1)
If IsArray($aFile) Then
_ArrayDelete($aFile, 0)
$aFile = CompareArray($aFile, $aRetFile)
For $i = 0 To UBound($aFile) - 1
FileDelete($Dir & "\" & $aFile[$i])
Next
EndIf
Func CompareArray($aA, $aB)
Local $Suffix = 0
While True
If $Suffix > UBound($aA) - 1 Then ExitLoop
For $i = 0 To UBound($aB) - 1
If $aB[$i] == $aA[$Suffix] Then
_ArrayDelete($aA, $Suffix)
$Suffix -= 1
ExitLoop
EndIf
Next
$Suffix += 1
WEnd
Return $aA
EndFunc
|