akira2891 Posted August 31, 2015 Share Posted August 31, 2015 (edited) Hi I have this piece of code i found in help file and it gives me partitions + other drives ( cd rom, usb, etc... )So how can i make this now to loop through drives and search for file "test.txt", i tried with _FileListToArray() but it gives me error 1 ( Path was invalid ).expandcollapse popup#include <Array.au3> #include <File.au3> #include <AutoItConstants.au3> Global $DT_ALL = "ALL", $aArray = DriveGetDrive($DT_ALL), $file = "test.txt" If @error Then ; An error occurred when retrieving the drives. MsgBox(0, "Error retrieving the drives", "Error : " & @error & ", Extended : " & @extended) Else For $i = 0 To $aArray[0] ; Show all the drives found and convert the drive letter to uppercase. ConsoleWrite("Drives : " & StringUpper($aArray[$i]) & @CRLF) ; debug ;~ $aFileList = _FileListToArray(StringUpper($aArray[$i]) & "\") ;~ If @error = 1 Then ;~ MsgBox(0, "", "Path was invalid.") ;~ Exit ;~ EndIf ;~ If @error = 2 Then ;~ MsgBox(0, "", "Invalid $sFilter.") ;~ Exit ;~ EndIf ;~ If @error = 3 Then ;~ MsgBox(0, "", "Invalid $iFlag.") ;~ Exit ;~ EndIf ;~ If @error = 4 Then ;~ MsgBox(0, "", "No file(s) were found.") ;~ Exit ;~ EndIf Next _ArrayDelete($aArray, 0) _ArrayDisplay($aArray, "test") ; debug ;~ _ArrayDisplay($aFileList, "$aFileList") EndIf Edited August 31, 2015 by akira2891 Link to comment Share on other sites More sharing options...
jguinch Posted August 31, 2015 Share Posted August 31, 2015 ?_FileListToArrayRec($aArray[$i] & "\", "test.txt", $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
akira2891 Posted August 31, 2015 Author Share Posted August 31, 2015 I tried this and i hear that it search on hard disk but it stops, no error, no result nothing. test.txt is on my D: drive so D:\text.txt but i dont get any errors or results#include <Array.au3> #include <File.au3> #include <AutoItConstants.au3> Global $DT_ALL = "ALL", $aArray = DriveGetDrive($DT_ALL), $file = "test.txt" If @error Then ; An error occurred when retrieving the drives. MsgBox(0, "Error retrieving the drives", "Error : " & @error & ", Extended : " & @extended) Else For $i = 0 To $aArray[0] ; Show all the drives found and convert the drive letter to uppercase. ;~ ConsoleWrite("Drives : " & StringUpper($aArray[$i]) & @CRLF) ; debug $aFileList = _FileListToArrayRec($aArray[$i] & "\", "test.txt", $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) If @error Then ConsoleWriteError($aFileList) EndIf Next _ArrayDelete($aArray, 0) ;~ _ArrayDisplay($aArray, "test") ; debug _ArrayDisplay($aFileList, "$aFileList") EndIf Link to comment Share on other sites More sharing options...
Celtic88 Posted August 31, 2015 Share Posted August 31, 2015 try this expandcollapse popupmsgbox(0,"",_Func_find_file_in_computer("jjjjjjjjjjjjjjjjjj")) Func _Func_find_file_in_computer($File_name, $type = "file") If $type = "" Then Return SetError(1, 1) $get_all_driv = DriveGetDrive("All") If @error Then Return SetError(@error, 2) For $ii = 1 To $get_all_driv[0] $findfile = _Func_find_file_in_spath($get_all_driv[$ii], $File_name, $type) If Not @error Then Return $findfile Next EndFunc ;==>_Func_find_file_in_computer Func _Func_find_file_in_spath($sch_Path, $File_name, $type) Local $hSearch = FileFindFirstFile($sch_Path & "\*.*") If @error Then Return SetError(1) Local $sFileName tooltip("find " & $File_name & " in " & $sch_Path) While 1 $sFileName = FileFindNextFile($hSearch) If @error Then ExitLoop If $type = "file" Then If Not @extended Then If $sFileName = $File_name Then Return $sch_Path & "\" & $sFileName Else $findfile = _Func_find_file_in_spath($sch_Path & "\" & $sFileName, $File_name, $type) If Not @error Then Return $findfile ContinueLoop EndIf Else If Not @extended Then ContinueLoop EndIf EndIf WEnd Return SetError(2) EndFunc ;==>_Func_find_file_in_spath Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 31, 2015 Moderators Share Posted August 31, 2015 akira2891,Of course it will not show anything - you keep overwriting the returned array as you test each drive, so there probably is nothing to display when you finally try to do so. Try this version:#include <Array.au3> #include <File.au3> #include <AutoItConstants.au3> Global $aArray = DriveGetDrive($DT_ALL), $file = "test.txt" If @error Then ; An error occurred when retrieving the drives. MsgBox(0, "Error retrieving the drives", "Error : " & @error & ", Extended : " & @extended) Else For $i = 1 To $aArray[0] $aFileList = _FileListToArrayRec($aArray[$i] & "\", $file, $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) If Not @error Then _ArrayDisplay($aFileList, "FileList for " & $aArray[$i]) EndIf Next EndIfThat finds the files for me.Celtic88,Why reinvent the wheel? We have a perfectly good recursive search function so no need to write another.M23 Celtic88 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
akira2891 Posted August 31, 2015 Author Share Posted August 31, 2015 This works and i see where it searching, thanks.But i just wonder why my example dont works ? I get list of all drives, and convert drive letters to uppercase like $aArray[1] ; is C: $aArray[2] ; is D: $aArray[3] ; is E: ( dvd rom ) $aArray[4] ; is F: ( dvd rom )now it just need to loop through them and search for a file but dont works. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 31, 2015 Moderators Share Posted August 31, 2015 akira2891, i just wonder why my example dont works ?Did you see my post (and amended example) above?M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
akira2891 Posted August 31, 2015 Author Share Posted August 31, 2015 Yea i see and i tested it now, its much faster than @Celtic88, only good thing in hes script is to show where is search but it search too long.Thanks for help. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 31, 2015 Moderators Share Posted August 31, 2015 akira2891,Glad I could help.M23 akira2891 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now