tylerh27 Posted August 2, 2012 Share Posted August 2, 2012 I want to scan certain folders, like the desktop, downloads, home folder for certain file types such as : .exe, .jpg, .png etc.. Then i want to list all the files in an alphanumerical order. It'll basically be a basic file explorer, in case you cant find like a certain file... also i'd like to search for sub directories, under like desktop or download folders. I'd really appreciate help on this! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 2, 2012 Moderators Share Posted August 2, 2012 tylerh27,Take a look at my ChooseFileFolder UDF - you can find the link in my sig below. It will give you a file tree with plenty of customisation options. If you want to write your own version, my RecFileListToArray UDF will give you an array of all the files on the path - it is what I use to produce the tree in the other UDF. And please ask if you have any questions about either of them. 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...
tylerh27 Posted August 3, 2012 Author Share Posted August 3, 2012 (edited) Yeah, i decided to try to do it with my own made script.. so far this is what i have: expandcollapse popup; Shows the filenames of all files in the current directory. Global $ex[3], $err, $search[3], $file $ex[0]="*.jpg*" $ex[1]="*.png*" $ex[2]="*.gif*" for $i=0 to 2 Local $search = FileFindFirstFile(@DesktopDir & "\" & $ex[$i]) Next ; Check if the search was successful If $search == $ex[0] Then $file = filefindnextfile($ex[0]) Else $err &= $ex[0] EndIf If $search == $ex[1] Then $file = filefindnextfile($ex[1]) Else $err &= $ex[1] EndIf If $search == $ex[2] Then $file = filefindnextfile($ex[2]) Else $err &= $ex[2] EndIf if $err Then MsgBox(0, "Error", $err & " doesnt exist") EndIf While 1 if $file Then MsgBox(4096, "File:", $file) Else Exit EndIf WEnd ; Close the search handle FileClose($search) I only have png images in my desktop directory, so it should give me an error for only jpg and gif, and display my png files... can you explain to me what i'm doing wrong? or if possible, some personal help would be greatly appreciated. Edited August 3, 2012 by tylerh27 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 3, 2012 Moderators Share Posted August 3, 2012 tylerh27, some personal help would be greatly appreciatedWe do not do that here - the whole idea of the forum is for everyone to see and learn. And do not worry about asking "newbie" questions - we were all beginners once! Why are you trying to code something yourself using FileFindFirst/NextFile when you can use UDFs to do the work for you? If you only want to look in a single folder for a single type of file then use _FileListToArray - if you want something rather more flexible then my _RecFileListToArray UDF has lots more options (scan the whole tree, look for multiple file types, etc, etc). One of the great things about AutoIt is the ease with which you can use UDFs developed by others in your code. As to the code you posted, I believe you can only have one search handle open at any one time, so you would need to put the whole search inside the For...Next loop. But try using the UDFS - it is much simpler - here it is with _FileListToArray: #include <File.au3> #include <Array.au3> ; Shows the filenames of jpg, png and gif files in the current directory. Global $aJPG, $aPNG, $aGIF $aJPG = _FileListToArray(@DesktopCommonDir, "*.jpg*", 1) If IsArray($aJPG) Then _ArrayDisplay($aJPG) Else MsgBox(0, "Desktop", "No JPG files found") EndIf $aJPG = _FileListToArray(@DesktopCommonDir, "*.png*", 1) If IsArray($aPNG) Then _ArrayDisplay($aPNG) Else MsgBox(0, "Desktop", "No PNG files found") EndIf $aGIF = _FileListToArray(@DesktopCommonDir, "*.gif*", 1) If IsArray($aGIF) Then _ArrayDisplay($aGIF) Else MsgBox(0, "Desktop", "No GIF files found") EndIf And here with RecFileListToArray: #include <RecFileListToArray.au3> #include <Array.au3> ; Shows the filenames of jpg, png and gif files in the current directory. Global $aImages $aImages = _RecFileListToArray(@DesktopCommonDir, "*.jpg*;*.gif*;*.gif", 1) If IsArray($aImages) Then _ArrayDisplay($aImages) Else MsgBox(0, "Desktop", "No files found") EndIf All clear? 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...
tylerh27 Posted August 4, 2012 Author Share Posted August 4, 2012 i got it to work with my own code, but i may use that since its less code.. also, is there a way to scan if there are sub directories? and the sub directories of those ones? it'd be nice if i could start a scan from root "C:" with a simple code if that's possible, cause i have no idea how to predict folders. On another note, i'm obviously new to this forum, can you tell me why i have posting limits, and cant send messages? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 4, 2012 Moderators Share Posted August 4, 2012 tylerh27,is there a way to scan if there are sub directories? and the sub directories of those ones?Yes, my RecFileListToArray UDF will let you scan as many levels down as you want - you just need to set the $iRecur parameter. As to posting and PMs, as a "Normal Member" you should have no posting restrictions - they are only in place for the first few posts. I have checked your PM settings and they are not blocking you - I have sent you a PM, try sending me one back. 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...
tylerh27 Posted August 5, 2012 Author Share Posted August 5, 2012 (edited) I got it working how i want, except for one thing, i just want to display the file names, and i want to excluding searching certain subdirectories, heres my new code: #include "Array.au3" #include "RecFileListToArray.au3" ; I scan all folders under the user profile directory for all image files, but i want to exclude the hidden directories such as APPData, but idk how to exclude searching those directories $aArray = _RecFileListToArray(@UserProfileDir & "", "*.png;*.jpg;*.gif", 1, 1, 1, 0, "", "AppData; Application Data; Cookies; Local Settings; NetHood; PrintHood; Searches; Templates") ConsoleWrite("Error: " & @error & " - " & " Extended: " & @extended & @CRLF) _ArrayDisplay($aArray, "Folder recur with filter") Can you tell me how i exclude those folders from the search? Edited August 5, 2012 by tylerh27 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 5, 2012 Moderators Share Posted August 5, 2012 tylerh27,If you just want the filenames, then set the $iReturnPath parameter to 0.If you want to exclude certain folders, then you need to set the $iReturn parameter to 0 (files and folders) - this activates the $sExclude_List_Folder parameter to exclude the folders you wish. You will get all the folders returned - but they will all end in "" so they are easy to remove from the returned array.So using this I get what you say you want:#include <RecFileListToArray.au3> #include <Array.au3> $aArray = _RecFileListToArray(@UserProfileDir & "", "*.png;*.jpg;*.gif", 0, 1, 1, 0, "", _ "AppData;Application Data;Cookies;Local Settings;NetHood;PrintHood;Searches;Templates") ConsoleWrite("Error: " & @error & " - " & " Extended: " & @extended & @CRLF) _ArrayDisplay($aArray, "Folder/file recur with filter") ; Create a new array to hold the images Global $aImages[UBound($aArray)] = [0] For $i = 1 To $aArray[0] ; If the element is a file If StringRight($aArray[$i], 1) <> "" Then ; Add to the image array $aImages[0] += 1 $aImages[$aImages[0]] = $aArray[$i] EndIf Next ; Resize the image array correctly ReDim $aImages[$aImages[0] + 1] _ArrayDisplay($aImages, "Files only")Are we there? 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...
tylerh27 Posted August 5, 2012 Author Share Posted August 5, 2012 (edited) I got it working somewhat how i want to.. except i have just two little problems.. first, the files show up with a "|" before them, and before the first one, it displays how many results there are, in my case 7. expandcollapse popup#include <GUIConstantsEx.au3> #include <RecFileListToArray.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) Global $search[15] Global $file[15] Global $img Global $list Global $listarray[2] = ["View Images", "View Excutables"] $list = "" For $i = 0 To UBound($listarray) = 2 $list &= "|" & $listarray[$i] Next GUICreate("File Explorer", 300, 300) GUICtrlCreateLabel("File Scanner", 0, 0) $combo = GUICtrlCreateCombo("", 0, 20, 100) GUICtrlSetData($combo, $list) $viewfile = GUICtrlCreateButton("Scan", 120, 20, 40) GUICtrlSetOnEvent($viewfile, "file") GUISetOnEvent($GUI_EVENT_CLOSE, "close") GUISetState(@SW_SHOW) while 1 sleep(1000) WEnd func file() $x = GuiCtrlRead($combo) if $x = "View Images" Then $filearray = "*.png;*.jpg;*.gif" ElseIf $x = "View Excutables" Then $filearray = "*.exe" Elseif $x = "" Then MsgBox(0, "Error", "You Must Chose A File Type") Return EndIf $aArray = _RecFileListToArray(@UserProfileDir & "", $filearray, 0, 1, 1, 0, "", _ "AppData;Application Data;Cookies;Local Settings;NetHood;PrintHood;Searches;Templates") ConsoleWrite("Error: " & @error & " - " & " Extended: " & @extended & @CRLF) ; Create a new array to hold the images Global $aImages[UBound($aArray)] = [0] For $i = 1 To $aArray[0] ; If the element is a file If StringRight($aArray[$i], 1) <> "" Then ; Add to the image array $aImages[0] += 1 $aImages[$aImages[0]] =" " & $aArray[$i] & @CRLF EndIf Next ; Resize the image array correctly ReDim $aImages[$aImages[0] + 1] $imglist = _ArrayToString($aImages) GUICtrlCreateLabel($imglist, 0, 40, 300, 300) EndFunc Func close() Exit EndFunc Edited August 5, 2012 by tylerh27 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 5, 2012 Moderators Share Posted August 5, 2012 tylerh27, the files show up with a "|" before them, and before the first one, it displays how many results there areYou need to read about functions when you use them: From the header for _RecFileListToArray: ; Return values .: Success: One-dimensional array made up as follows: ; |$array[0] = Number of FilesFolders returned And from the Help file for _ArrayToString: $iStart [optional] Index of array to start combining at - Return Value Success: string which combined selected elements separated by the delimiter string. So you need to set the $iStart parameter to 1 to omit the count element. And if you do not have a delimiter (which in AutoIt is "|" by default) how can you distinguish between the different filenames in the resultant string? What do you intend to do with the string? You might be better off in some other format. 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...
tylerh27 Posted August 5, 2012 Author Share Posted August 5, 2012 ahhh okay lol, the array to string was that was wrong.. it works perfectly now thank you so much! 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