OldMike Posted February 1, 2011 Share Posted February 1, 2011 Need to simply count the number of files in a folder. Found postings re: FileListToArray, but it is not listed in the on line documentation of functions. Mike Link to comment Share on other sites More sharing options...
enaiman Posted February 1, 2011 Share Posted February 1, 2011 You should have been able to find it in the online help ... but here it is: quoting from the AutoIT help file. _FileListToArray -------------------------------------------------------------------------------- Lists files and\or folders in a specified path (Similar to using Dir with the /B Switch) #Include <File.au3> _FileListToArray($sPath [, $sFilter = "*" [, $iFlag = 0]]) Parameters $sPath Path to generate filelist for. $sFilter [optional] the filter to use, default is *. Search the Autoit3 helpfile for the word "WildCards" For details. $iFlag [optional] specifies whether to return files folders or both $iFlag=0(Default) Return both files and folders $iFlag=1 Return files only $iFlag=2 Return Folders only Return Value Success: an Array, see remarks Failure: 0 @Error: 1 = Path not found or invalid 2 = Invalid $sFilter 3 = Invalid $iFlag 4 = No File(s) Found Remarks The array returned is one-dimensional and is made up as follows: $array[0] = Number of Files\Folders returned $array[1] = 1st File\Folder $array[2] = 2nd File\Folder $array[3] = 3rd File\Folder $array[n] = nth File\Folder Related Example #Include <File.au3> #Include <Array.au3> $FileList=_FileListToArray(@DesktopDir) If @Error=1 Then MsgBox (0,"","No Folders Found.") Exit EndIf If @Error=4 Then MsgBox (0,"","No Files Found.") Exit EndIf _ArrayDisplay($FileList,"$FileList") SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
whim Posted February 1, 2011 Share Posted February 1, 2011 Try searching the help file for "_FileListToArray" (note leading "_") HTH, whim Link to comment Share on other sites More sharing options...
enaiman Posted February 1, 2011 Share Posted February 1, 2011 (edited) Nevermind - just seen my post now Edited February 1, 2011 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
OldMike Posted February 2, 2011 Author Share Posted February 2, 2011 Thanks; just what I need. So, there are functions documented in the editor Help that are not listed in the on line documentation list of functions???? Seems simple to copy one into the other. Mike Link to comment Share on other sites More sharing options...
MvGulik Posted February 2, 2011 Share Posted February 2, 2011 (edited) whatever Edited February 7, 2011 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
GEOSoft Posted February 2, 2011 Share Posted February 2, 2011 (edited) I have a hunch the OP did not take a look at the "User Defined Functions" part of the help file. Those functions are not native to AutoIt and _FileListToArray() is one of them under "File Management"EDIT: I'm not sure if it is actually included in the official On-line docs for AutoIt but it is in my on-line docs and that link is in my signature although I should probaly modify my signature to show it is not the normal AutoIt On-line. Edited February 2, 2011 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
OldMike Posted February 3, 2011 Author Share Posted February 3, 2011 I have four files to check, all are in D:, named P1, P2, P3, P4. I need to check the number of PDF files in each. It seems this should work, runs without errors, but returns null. #include<file.au3> #Include<array.au3> Global $fcnt[1] For $n = 1 to 4 $path = _Pathmake("D:","\P"&$n,"\*.pdf","") $fcnt[0] = _FileListToArray($path) MsgBox(0,"","Number of files in P" & $n & " is: "&$fcnt[0]) Next Link to comment Share on other sites More sharing options...
BrewManNH Posted February 3, 2011 Share Posted February 3, 2011 First, you're not reading the files in the path, you're trying to read the files in a path name that contains the return result of your function _Pathmake, which is probably equivalent to _FileListToArray(0) where the 0 is the path the function is trying to read from. Second, use $fcnt = _FileListToArray($path) without the [0] element of the array. _FileListToArray returns an array of file names and puts them into your array, and the [0] element holds the number of files it finds, you just need to use the array name to have everything put into the array correctly. 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 GudeHow 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 More sharing options...
OldMike Posted February 3, 2011 Author Share Posted February 3, 2011 I removed [0] from the $fcnt = _FileListToArray($path), then got an error message on the line with msgbox unless I deleted it there too. The error message is "Subscript used on nonarray variable." When I do remove it on that line too, I am back to a null result. I don't understand your comment about the path; could you suggest how that line should read? I am trying to read from: D:\P1 D:\P2 D:\P3 D:\p4 Thanks for your patience. Mike Link to comment Share on other sites More sharing options...
OldMike Posted February 3, 2011 Author Share Posted February 3, 2011 OK, got it going now. Doesn't square with the documentation, but it works: #include<file.au3> #Include<array.au3> Global $fcnt For $n = 1 to 4 $path = "D:\P" & $n $fcnt = _FileListToArray($path,"*.pdf",1) MsgBox(0,"","Number of files in P" & $n & " is: "&$fcnt[0]) Next Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2011 Moderators Share Posted February 4, 2011 OldMike,Doesn't square with the documentationYes it does - why do you think it does not? 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...
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