Jump to content

Search the Community

Showing results for tags 'zero-byte'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. List (and, optionally, Delete) 0-byte files in current or specified directory; optionally, recurse through subdirectories. The heart of the matter is func _ListZeroByteFiles(). #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=ListZero.exe #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #AutoIt3Wrapper_Run_Au3Stripper=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; ; List (and, optionally, Delete) Zero-byte Files ; in current|specified directory ; Optionally, recurse through subdirs ; CLD rev. 2021-06-20 ; #cs Usage ----- ListZero d:\path1[ d:\path2 ...] [/R] [/-A] [/V] [/D[R]] /X:exclude_file [/?|/H] d:\path Path(s) to search (at least one is *required*) /R Recurse through subdirectories /-A Omit check for alternative data streams (ADS) /V Verbose: list subdirectory names in addition to files /D Delete listed files (NOT recommended on system drive) /DR Move listed files to Recycle bin /X:exclude_file Exclude files with *extensions* listed in exclude_file (one extension per line) /?|/H Help #ce #include <Misc.au3> #include <WinAPIFiles.au3> Global $sDir = "." Global $bSubDirs = 0, $sMsg = "", $iDeles = 0, $iFiles = 0, $bQuiet = 1 Global $sWinDrive = StringLeft(@WindowsDir, 2), $sTestStr = $sDir Global $vDele = 0, $sDeleWord = "", $sLastWord = "Deleted" Global $sExtFn = "", $aExts, $sExExts = "" Global $bADS = 1, $bNTFS = 0, $iRecurseLimit = 0 ; Test for at least one dir in command Global $p = $CmdLine[0] If $p Then For $i = 1 To $CmdLine[0] If StringInStr($CmdLine[$i], "/") = 1 Then $p -= 1 Next EndIf If $p < 1 Or StringInStr($CmdLineRaw, "/?") Or StringInStr($CmdLineRaw, "/H") Then Exit Consolewrite("List (and, optionally, Delete) Zero-byte Files [CLD rev.2021-02-07]" & @CRLF & @CRLF & StringTrimRight(@ScriptName, 4) & " d:\path1[ d:\path2 ...] [/R] [/-A] [/V] [/D[R]] /X:exclude_file [/?|/H]" & @CRLF & @CRLF & "d:\path Path(s) to search (at least one is *required*)" & @CRLF & "/R Recurse through subdirectories" & @CRLF & "/-A Omit check for alternate data streams (ADS)" & @CRLF & "/V Verbose: list subdirectory names in addition to files" & @CRLF & "/D Delete listed files (NOT recommended on system drive)" & @CRLF & "/DR Move listed files to Recycle bin" & @CRLF & "/X:exclude_file" & @CRLF & " Exclude files with *extensions* listed in exclude_file" & @CRLF & " (one extension per line)" & @CRLF & "/?|/H Help" & @CRLF) If StringInStr($CmdLineRaw, "/R") Then $bSubDirs = 1 If StringInStr($CmdLineRaw, "/-A") Then $bADS = 0 If StringInStr($CmdLineRaw, "/D") Then $vDele = 2 $sDeleWord = "Delet" If StringInStr($CmdLineRaw, "/DR") Then $vDele = 1 $sDeleWord = "Recycl" EndIf $sDeleWord &= "ed ==> " EndIf If StringInStr($CmdLineRaw, "/V") Then $bQuiet = 0 If StringInStr($CmdLineRaw, "/X:") Then $sExtFn = StringTrimLeft($CmdLineRaw, 2 + StringInStr($CmdLineRaw, "/X:")) While StringInStr($sExtFn, " ") = 1 $sExtFn = StringTrimLeft($sExtFn, 1) WEnd If StringInStr($sExtFn, """") = 1 Then $sExtFn = StringTrimLeft($sExtFn, 1) If StringInStr($sExtFn, """") Then $sExtFn = _ StringTrimRight($sExtFn, StringLen($sExtFn) - StringInStr($sExtFn, """")) Else If StringInStr($sExtFn, " ") Then $sExtFn = StringTrimRight($sExtFn, StringLen($sExtFn) - StringInStr($sExtFn, " ")) EndIf If FileExists($sExtFn) Then Global $h1 = FileOpen($sExtFn) $sExExts = FileRead($h1) FileClose($h1) If $sExExts Then If StringInStr($sExExts, @CRLF) Then $aExts = StringSplit($sExExts, @CRLF) $sExExts = "." For $i = 1 To $aExts[0] If $aExts[$i] Then $sExExts &= $aExts[$i] & "." Next Else $sExExts = "." & $sExExts & "." EndIf EndIf EndIf EndIf If $vDele = 2 And StringInStr($CmdLineRaw, $sWinDrive) Then ConsoleWrite("Warning: Deleting zero-byte files in the system drive (" & $sWinDrive & ") is not recommended." & @CRLF & "Are you sure you want to continue? (y|N)" & @CRLF) Global $hDLL = DLLOpen("user32.dll") While 1 If _IsPressed("59", $hDLL) Then ConsoleWrite(@CRLF) ExitLoop ElseIf _IsPressed("1B", $hDLL) Or _IsPressed("4E", $hDLL) Then DLLClose($hDLL) ConsoleWrite(@CRLF & "Quitting..." & @CRLF) Exit Else Sleep(20) EndIf WEnd DLLClose($hDLL) EndIf If $bSubDirs Then ConsoleWrite("Working... (Ctrl+C quits)" & @CRLF) For $i = 1 To $CmdLine[0] If StringInStr($CmdLine[$i], "/") = 1 Then ContinueLoop If $CmdLine[$i - 1] = "/X" Then ContinueLoop If StringRight($CmdLine[$i], 1) <> "\" Then $CmdLine[$i] &= "\" $CmdLine[$i] &= "\" $bNTFS = _SetbNTFS($CmdLine[$i]) $iDeles += _ListZeroByteFiles($CmdLine[$i], $bSubDirs) Next If $vDele = 1 Then $sLastWord = "Recycled" Global $iDiff = 7 + StringLen("Deleted") - StringLen($sLastWord) $sMsg = "Found " & StringFormat("%7s", _IntFormat($iFiles)) & " " & _OneMany("file", $iFiles) & @CRLF & $sLastWord & " " & StringFormat("%" & String($iDiff) & "s", _IntFormat($iDeles)) & " " & _OneMany("file", $iDeles) Exit ConsoleWrite(@CRLF & $sMsg & @CRLF) ;--- Func _ListZeroByteFiles($sPath = ".", $bRecurs = 0) ; List|Delete 0-byte files in current or specified directory ; Optionally, recurse through subdirectories ; Returns number of 0-byte files deleted $iRecurseLimit += 1 If $iRecurseLimit = 200 Then $iRecurseLimit = 0 Return EndIf If StringRight($sPath, 1) <> "\" Then $sPath &= "\" If StringRight($sPath, 1) = "\" Then $sPath &= "*" If Not FileExists($sPath) Then Return 0 Local $sFn = "", $iC = 0, $iC2 = 0, $bEx = 0 Local $sDirName = _FileGetPath($sPath) Local $h = FileFindFirstFile($sPath) If $h = -1 Then Return 0 While 1 $sFn = $sDirName & "\" & FileFindNextFile($h) If @error Then FileClose($h) ExitLoop EndIf $bEx = @extended If StringInStr($sFn, ":") = 2 Then $sFn = StringUpper(StringLeft($sFn, 1)) & StringTrimLeft($sFn, 1) If $bEx = 0 Then; we have a file If _FileGetSizeADS($sFn) = 0 Then If $sExExts Then If StringInStr($sExExts, "." & _FileGetExt($sFn) & ".") Then ContinueLoop EndIf $iFiles += 1 Switch $vDele Case 0 Case 1 If FileRecycle($sFn) Then $iC += 1 Case 2 If FileDelete($sFn) Then $iC += 1 EndSwitch ConsoleWrite($sDeleWord & $sFn & @CRLF) EndIf Else; we have a directory If $bRecurs Then If $bQuiet = 0 Then ConsoleWrite("Searching " & $sFn & @CRLF) $iC2 = _ListZeroByteFiles($sFn, 1) If $iC2 > 0 Then $iC += $iC2 $iC2 = 0 EndIf EndIf WEnd Return $iC EndFunc ;==>_ListZeroByteFiles Func _FileGetExt($sFn) ; Parse ext from [d:\path\]filename.ext Local $sExt = "", $aA If StringInStr($sFn, ".") Then If StringInStr(FileGetAttrib($sFn), "D") Then Return $sExt $aA = StringSplit($sFn, ".") $sExt = $aA[$aA[0]] EndIf Return $sExt EndFunc ;==>_FileGetExt Func _FileGetPath($sFn) ; Parse directory from path\file; final "\" is trimmed Local $sDirr = "" Local $aA = StringSplit($sFn, "\") Local $iS = $aA[0] - 1 If Not StringInStr(FileGetAttrib($aA[$aA[0]]), "D") Then $iS += 1 For $i = 1 To $iS $sDirr &= $aA[$i] & "\" Next While StringRight($sDirr, 1) = "\" $sDirr = StringTrimRight($sDirr, 1) WEnd Return $sDirr EndFunc ;==>_FileGetPath Func _FileGetSizeADS($sFile) Local $sErrW, $sFnTmp, $aFnTmp Local $iSize = FileGetSize($sFile) If Not ($bADS And $bNTFS) Then Return $iSize $iSize = 0 Local $pData = _WinAPI_CreateBuffer(1024) Local $tFSD = DllStructCreate($tagWIN32_FIND_STREAM_DATA) Local $hSearch = _WinAPI_FindFirstStream($sFile, $tFSD) While Not @error $iSize += DllStructGetData($tFSD, 'StreamSize') _WinAPI_FindNextStream($hSearch, $tFSD) WEnd Switch @extended Case 38 ; ERROR_HANDLE_EOF Case Else $sErrW = _WinAPI_GetErrorMessage(@extended) $aFnTmp = StringSplit($sFile, "\") $sFnTmp = $aFnTmp[$aFnTmp[0]] If Not StringRight($sErrW, 13) = "successfully." Then _ ConsoleWrite("--> " & $sFnTmp & ": " & $sErrW & @CRLF) EndSwitch _WinAPI_FindClose($hSearch) _WinAPI_FreeMemory($pData) Return $iSize EndFunc ;==>_FileGetSizeADS Func _IntFormat($n, $s = ",", $sd = ".") ; Insert commas|specified separator into integer If StringIsInt($n) Then Local $a, $d = "", $x If StringInStr($n, $sd) Then $a = StringSplit($n, $sd) $n = $a[1] $d = $sd & $a[2] EndIf $x = $n $n = "" While StringLen($x) > 3 $n = $s & StringRight($x, 3) & $n $x = StringTrimRight($x, 3) WEnd $n = $x & $n EndIf Return ($n & $d) EndFunc ;==>_IntFormat Func _OneMany($sSingular, $iCount, $sPlural = "") ; Returns singular or plural depending on count ; Plural appends S to singular (ES if it ends in S) ; unless $sPlural is supplied Local $sEss = "s" If StringRight($sSingular, 1) = "s" Then $sEss = "es" If StringUpper($sSingular) == $sSingular Then $sEss = StringUpper($sEss) If Not $sPlural Then $sPlural = $sSingular & $sEss If Abs($iCount) = 1 Then Return $sSingular Else Return $sPlural EndIf EndFunc ;==>_OneMany Func _SetbNTFS($sPath) If DriveGetFileSystem(StringLeft($sPath, 3)) = "NTFS" Then Return 1 Else Return 0 EndIf EndFunc ;==>_SetbNTFS
×
×
  • Create New...