Jump to content

Search Files


Recommended Posts

Nice idea Spiff59, didn't think about the DIR command. Another one could've been 'forfiles', which I'm sure I have a function for in my snippet folder.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

BTW, the line $sFilePath = $sPath1 & '' & $aFileList[$i] is wrong, you have _RecFileListToArray configured to return the filename with the full path included, you're actually adding the full path to the file name twice this way. The returned filename is going to look like this, C:DataC:Datatest.txt after you're run that line.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

BTW, the line $sFilePath = $sPath1 & '' & $aFileList[$i] is wrong, you have _RecFileListToArray configured to return the filename with the full path included, you're actually adding the full path to the file name twice this way. The returned filename is going to look like this, C:DataC:Datatest.txt after you're run that line.

Ah, stupid me. Sorry. I forgot to edit that part.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

stealthmsgr,

See my previous code. I fixed the issue reported by BrewManNH (thanks for that by the way.)

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

My prior example was not very useful in this case as the /s (include subfolders) parameter was left off the DIR command.

Inserting "/s" caused the function to fail due to it's dependence on the embedded sort-by-filesize parameter "/O-S", that will only sort at the directory level, rather than globally. So, after a few tweaks, this is version 2. I don't expect the OP to adopt it, but am willing to bet it runs circles around any options using FileGetSize(). On this PC, the 4 executions in the sample script below return between 8800 and 28400 files and all run in between 3.1 and 3.5 seconds.

#include <Array.au3>

Local $test[4][2] = [[">", 99999],["<", 100000],[">", -1],[">", 0]]

For $x = 0 to 3
    $timer = TimerInit()
    $array = _DOSRecFLTABySize(@WindowsDir, $test[$x][0], $test[$x][1])
    $timer = TimerDiff($timer) / 1000
    _ArrayDisplay($array, "Files " & $test[$x][0] & " " & $test[$x][1] & " in " & Round($timer, 2) & " seconds") ; for testing
Next

;===================================================================================================================================
Func _DOSRecFLTABySize($sDirectory, $g_or_l, $iSize)
    Local $sStdOut, $iIndex = 0
    $PID = Run(@ComSpec & ' /c DIR /s "' & $sDirectory & '" /A-D /-C', '', @SW_HIDE, 0x2) ; 0x2 = $STDOUT_CHILD
    While Not @error
        $sStdOut &= StdoutRead($PID)
    WEnd
    $aStdOut = StringSplit($sStdOut, @CRLF)
    For $x = 1 To $aStdOut[0] ; pack and format array
        If StringMid($aStdOut[$x], 3, 1) = "/" Then
            $aStdOut[$x] = StringStripWS($aStdOut[$x], 7)
            $aStdOut[$x] = StringTrimLeft($aStdOut[$x], StringInStr($aStdOut[$x], " ", 2, 3)) ; strip date/time
            If $g_or_l = ">" Then
                If $aStdOut[$x] <= $iSize Then ContinueLoop
            Else
                If $aStdOut[$x] >= $iSize Then ContinueLoop
            EndIf
            $iIndex += 1
;          $aStdOut[$iIndex] = $aStdOut[$x] ; leave filesize intact
            $aStdOut[$iIndex] = StringTrimLeft($aStdOut[$x], StringInStr($aStdOut[$x], " ", 2, 1)) ; strip filesize
        EndIf
    Next
    $aStdOut[0] = $iIndex
    ReDim $aStdOut[$iIndex + 1]
    Return $aStdOut
EndFunc
Link to comment
Share on other sites

Sanity check

Guys, as you know I'm working on a simple(?!?!) file size verification component of my project.

This is a new hunk of code that I was playing with to do this.

; Shows the filenames of all files in the current directory
Local $search = FileFindFirstFile("C:Data*.txt")
Global $compare, $size, $zerosize = 0, $name
; Check if the search was successful
If $search = -1 Then
MsgBox(0, "Error", "No files/directories matched the search pattern")
Exit
EndIf

While 1
Global $file = FileFindNextFile($search)
If @error Then ExitLoop
_FileCompare ($compare)

MsgBox(4096, "File:", $file)
WEnd

; Close the search handle
FileClose($search)

Func _FileCompare ($compare)
Local $size = FileGetSize($file)
If $size = $zerosize Then
$name = FileRead($file, -1)
MsgBox(0, "Info", "File Size: " & $file)
EndIf
Exit
EndFunc

Guinness, this is a somewhat variation of yours and JohnOne's.

Something I was playing with. Something screwy here though.

I seems instead of testing the actual size of the file (I was going for) it seems to test the name size, i.e. 1111.txt is smaller than 11112.txt

I didn't catch it a first because the files being generated are random and about 15-20 characters long.

Can you look at it and point out why I'm not actually testing the actual file size (say in 1K bytes, etc.). I have a suspicion but I need another quick look.

Maddening, Yikes, you wouldn't think it would be this bloody hard~!?

Link to comment
Share on other sites

Shouldn't this => MsgBox(0, "Info", "File Size: " & $file) be like this => MsgBox(0, "Info", "File Size: " & $size)?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Try this code, the file compare function now returns TRUE if the file isn't zero bytes in size. The consolewrites are displaying the return from the function.

; Shows the filenames of all files in the current directory
Local $search = FileFindFirstFile("C:Data*.txt")
Global $compare, $size, $zerosize = 0, $name
; Check if the search was successful
If $search = -1 Then
     MsgBox(0, "Error", "No files/directories matched the search pattern")
     Exit
EndIf
While 1
     Global $file = FileFindNextFile($search)
     If @error Then ExitLoop
     $Return = _FileCompare("C:Data" & $file) ; you need the original path in front of the file name
     ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Return = ' & $Return & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
;~    MsgBox(4096, "File:", $file)
WEnd
; Close the search handle
FileClose($search)
Func _FileCompare($compare)
     Local $size = FileGetSize($compare)
     ; NOTE: Returns true if the file is NOT zero bytes, change to: Return Not $size <> $zerosize to return a true if file IS zero bytes
     Return $size <> $zerosize
EndFunc   ;==>_FileCompare

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Here's another version that also includes the filemove. I've also included an alternate version that doesn't use the function _FileCompare, your choice. :)

; Shows the filenames of all files in the current directory
$Path = "C:Data"
Local $search = FileFindFirstFile($Path & "*.txt")
Global $compare, $size, $zerosize = 0, $name
; Check if the search was successful
If $search = -1 Then
     MsgBox(0, "Error", "No files/directories matched the search pattern")
     Exit
EndIf

While 1
     Global $file = FileFindNextFile($search)
     If @error Then ExitLoop
     $file = $Path & $file
     If Not _FileCompare($file) Then ; if the file is zero bytes, this returns False, so it moves that file
          ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $file = ' & $file & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
;~           FileMove($file, "<file move destination>")
     EndIf
WEnd
#cs
; Alternate version below
While 1
     Global $file = FileFindNextFile($search)
     If @error Then ExitLoop
     $file = $Path & $file
     If Not Filegetsize($file) <> $zerosize Then ; if the file is zero bytes, move that file
          ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $file = ' & $file & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
;~           FileMove($file, "<file move destination>")
     EndIf
WEnd
#ce
; Close the search handle
FileClose($search)
Func _FileCompare($compare)
     Local $size = FileGetSize($compare)
     ; NOTE: Returns true if the file is NOT zero bytes, change to: Return Not $size <> $zerosize to return a true if file IS zero bytes
     Return $size <> $zerosize
EndFunc   ;==>_FileCompare

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Works like a champ BrewMan!!

I have learned a great deal from something that I thought was going to be quick and easy!

I now have to integrate this into the rest of my code and clean it all up.

Thank you very much for the lesson.

Hopefully I can be of assistance and/or pay some of this forward.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...