About This File
Ever wanted to make a list for those mp3 files you have sitting in a directory?
Ever wanted to make a list of any files on your computer?
Look no further... I have made a simple script to do such that!
Logged 131,000 files under 60 seconds. (My whole C:\ with *.*)
==============================================================
============= S C R E E N S H O T S =============
==============================================================
==============================================================
============= C H A N G E L O G =============
==============================================================
v1.04 - Added a Timer to show how long it took to search.
v1.03 - Added support to search for multiple file extenstions.
v1.02 - Changed from searching only Mp3's to All files.
v1.01 - Made adjustments to searching.
Added Melba23's _FileListToArray_Recursive
v1.00 - Initail Release
==============================================================
============= S O U R C E =============
==============================================================
Using Melba23's _FileListToArray_Recursive
#include <File.au3>#include <GUIConstants.au3>#include <Array.au3>Global $temppath = @ScriptDirGUICreate("Inventory", 320, 265, -1, @DesktopHeight/10)GUICtrlCreateLabel("Inventory v1.04 - Created by Rogue5099", 42, 5, 375, 20)$Button_1 = GUICtrlCreateButton("Take Invenotry", 200, 34, 100, 50)$Checkbox_1 = GUICtrlCreateCheckbox("Include Subfolders", 10, 30)$Checkbox_2 = GUICtrlCreateCheckbox("Include Full File Path", 10, 55)GUICtrlCreateLabel("File type to search for. i.e. .jpg,.mp3 (Seperate /w Comma):", 8, 97, 325, 20)Global $Input3 = GUICtrlCreateInput("*.*", 25, 117, 240, 20)GUICtrlCreateLabel("Save Inventory File to:", 8, 147, 125, 20)Global $Input1 = GUICtrlCreateInput(@ScriptDir, 25, 167, 240, 20)$Browse_1 = GUICtrlCreateButton("...", 270, 167, 30, 20)GUICtrlCreateLabel("Scan directory for file(s):", 8, 197, 125, 20)Global $Input2 = GUICtrlCreateInput(@ScriptDir, 25, 217, 240, 20)$Browse_2 = GUICtrlCreateButton("...", 270, 217, 30, 20)GUICtrlCreateLabel("Progress:", 90, 240, 65, 20)GUICtrlSetFont (-1, 10, 600)Global $Label_1 = GUICtrlCreateLabel("Waiting", 165, 240, 95, 20)GUICtrlSetFont (-1, 10, 600)GUISetState (@SW_SHOW)While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 GUICtrlSetData($Label_1, "Scanning...") $Timer = TimerInit() GUICtrlSetFont (-1, 10, 600) GUICtrlSetColor(-1, 16711680) $ext = StringSplit(GUICtrlRead($Input3), ",") $Amount = StringTrimRight(_ArrayToString($ext), StringLen(_ArrayToString($ext) - 2)) $Text = GUICtrlRead($Input1) & "Inventory.txt" If FileExists($Text) Then FileDelete($Text) For $x = 1 To $Amount If BitAND(GUICtrlRead($Checkbox_1), $GUI_CHECKED) = $GUI_CHECKED And BitAND(GUICtrlRead($Checkbox_2), $GUI_CHECKED) = $GUI_CHECKED Then $Inventory = _FileListToArray_Recursive(GUICtrlRead($Input2), $ext[$x], 1, 2, True) If @Error = 4 Then MsgBox (48,"Error","No "&$ext&" Files Found.", 5) ElseIf BitAND(GUICtrlRead($Checkbox_1), $GUI_CHECKED) = $GUI_CHECKED And BitAND(GUICtrlRead($Checkbox_2), $GUI_UNCHECKED) = $GUI_UNCHECKED Then $Inventory = _FileListToArray_Recursive(GUICtrlRead($Input2), $ext[$x], 1, 0, True) If @Error=4 Then MsgBox (48,"Error","No "&$ext&" Files Found.", 5) ElseIf BitAND(GUICtrlRead($Checkbox_1), $GUI_UNCHECKED) = $GUI_UNCHECKED And BitAND(GUICtrlRead($Checkbox_2), $GUI_CHECKED) = $GUI_CHECKED Then $Inventory = _FileListToArray_Recursive(GUICtrlRead($Input2), $ext[$x], 1, 2, False) If @Error=4 Then MsgBox (48,"Error","No "&$ext&" Files Found.", 5) Else $Inventory = _FileListToArray_Recursive(GUICtrlRead($Input2), $ext[$x], 1, 0, False) If @Error=4 Then MsgBox (48,"Error","No "&$ext&" Files Found.", 5) EndIf $aText = FileOpen($Text, 1) _FileWriteFromArray($aText, $Inventory, 1) FileClose($aText) Next $Time = TimerDiff($Timer) $Time = Round($Time / 1000, 3) GUICtrlSetData($Label_1, "Done") GUICtrlSetFont (-1, 10, 600) GUICtrlSetColor(-1, 32768) Sleep(2000) $CountLines = (_FileCountLines($Text)) If $CountLines > 0 Then MsgBox(1, "Info", "Number of file(s) in folder(s): " & $Countlines & @CRLF & "Scanned in " & $Time & " seconds." & @CRLF & "List saved at: " & $Text) Run("notepad.exe " & $Text) EndIf Case $msg = $Browse_1 $temppath = FileSelectFolder("Save File Where", "", 1, @ScriptDir) GUICtrlSetData($Input1, $temppath) Case $msg = $Browse_2 $temppath = FileSelectFolder("Choose a folder to search.", "", 1, @ScriptDir) GUICtrlSetData($Input2, $temppath) EndSelectWendFunc _FileListToArray_Recursive($sPath, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 0, $bRecursive = False) Local $sRet = "", $sRetPath = "" $sPath = StringRegExpReplace($sPath, "[/]+z", "") If Not FileExists($sPath) Then Return SetError(1, 1, "") If StringRegExp($sFilter, "[/ :> <|]|(?s)As*z") Then Return SetError(2, 2, "") $sPath &= "|" $sOrigPathLen = StringLen($sPath) - 1 While $sPath $sCurrPathLen = StringInStr($sPath, "|") - 1 $sCurrPath = StringLeft($sPath, $sCurrPathLen) $Search = FileFindFirstFile($sCurrPath & $sFilter) If @error Then $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1) ContinueLoop EndIf Switch $iRetPathType Case 1 ; relative path $sRetPath = StringTrimLeft($sCurrPath, $sOrigPathLen) Case 2 ; full path $sRetPath = $sCurrPath EndSwitch While 1 $File = FileFindNextFile($Search) If @error Then ExitLoop If ($iRetItemType + @extended = 2) Then ContinueLoop $sRet &= $sRetPath & $File & "|" WEnd FileClose($Search) If $bRecursive Then $hSearch = FileFindFirstFile($sCurrPath & "*") While 1 $File = FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then $sPath &= $sCurrPath & $File & "|" WEnd FileClose($hSearch) EndIf $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1) WEnd If Not $sRet Then Return SetError(4, 4, "") Return StringSplit(StringTrimRight($sRet, 1), "|")EndFunc ;==> Melba23's _FileListToArray_Recursive
Recommended Comments
There are no comments to display.