找回密码
 加入
搜索
查看: 2012|回复: 0

[系统综合] 求 _delelt UDF(删除文件的UDF)

[复制链接]
发表于 2010-9-14 16:00:40 | 显示全部楼层 |阅读模式
本帖最后由 wjscxs 于 2010-9-24 10:44 编辑
Func _DeleteFile($sFile, $sExclude = "", $iFlag = 0)
        Local $Path, $FileList[1], $ExcludeList[1] = [0], $FileSystem = "", $Element, $FileAttrib, $Result = 0

        If StringRight($sFile, 1) = "" Then $sFile = StringTrimRight($sFile, 1)
        $Path = StringLeft($sFile, StringInStr($sFile, "", 0, -1))
        $sFile = StringTrimLeft($sFile, StringInStr($sFile, "", 0, -1))
        If $Path = "" Then $Path = @WorkingDir & ""
        If Not FileExists($Path) Or Not StringInStr(FileGetAttrib($Path), "D") Or $sFile = "" Then Return 1
        If StringRegExp($sExclude, '^.*[\\/:*?"<>]+.*$') Then Return SetError(2, 0, 0)
        If $iFlag <> 0 And $iFlag <> 1 And $iFlag <> 2 Then Return SetError(3, 0, 0)

        $FileList = _FileListToArray($Path, $sFile, $iFlag)
        If @error Then Return 1

        If $sExclude <> "" Then $ExcludeList = StringSplit($sExclude, "|")
        $FileSystem = DriveGetFileSystem($Path)
        If $FileSystem = "NTFS" Then
                _ArrayAdd($ExcludeList, "System Volume Information")
                $ExcludeList[0] = UBound($ExcludeList) - 1
        EndIf

        For $i = 1 To $ExcludeList[0]
                $Element = _ArraySearch($FileList, $ExcludeList[$i], 1)
                If $Element <> -1 Then _ArrayDelete($FileList, $Element)
        Next
        $FileList[0] = UBound($FileList) - 1

        For $i = 1 To $FileList[0]
                If $FileList[$i] = "RECYCLER" And $FileSystem <> "" Then
                        _DeleteFile($Path & $FileList[$i] & "\*.*")
                        If @error Then $Result = 1
                        ContinueLoop
                EndIf

                $FileAttrib = FileGetAttrib($Path & $FileList[$i])
                If StringRegExp($FileAttrib, ".*[RSH]+.*") Then FileSetAttrib($Path & $FileList[$i], "-RSH")
                If StringInStr($FileAttrib, "D") Then
                        If Not DirRemove($Path & $FileList[$i], 1) Then
                                _DeleteFile($Path & $FileList[$i] & "\*.*")
                                $Result = 1
                        EndIf
                Else
                        If Not FileDelete($Path & $FileList[$i]) Then $Result = 1
                EndIf
        Next

        If $Result Then
                Return SetError(1, 0, 0)
        Else
                Return 1
        EndIf
EndFunc   ;==>_DeleteFile
感谢HOOK大哥再次提供UDF
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-15 02:28 , Processed in 0.072091 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表