Ram Posted December 13, 2011 Share Posted December 13, 2011 (edited) I am looking for a way to get number of files in a folder (specific extension - for e.g (pdf)) - Is it possible - if so can you guide me please? Thanks! Edited December 13, 2011 by Ram Link to comment Share on other sites More sharing options...
somdcomputerguy Posted December 13, 2011 Share Posted December 13, 2011 This should get you started - FileFindFirstFile - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Ram Posted December 13, 2011 Author Share Posted December 13, 2011 (edited) This should get you started - FileFindFirstFile Yeah I have seen this...Altered it was trying couldn't achieve what I wanted... Here is what I tried: ; Shows the filenames of all files in the current directory. $location = ("D:Temppdfs") $search = FileFindFirstFile($location & "*.pdf") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = DirGetSize($search) If @error Then ExitLoop Msgbox(0, "", $file[1]) WEnd ; Close the search handle FileClose($search) Didn't give me any results.. Edited December 13, 2011 by Ram Link to comment Share on other sites More sharing options...
JohnOne Posted December 13, 2011 Share Posted December 13, 2011 (edited) $iFiles = _NumFiles(@ScriptDir,"*.pdf",1) MsgBox(0,"Files",$iFiles) Func _NumFiles($sPath, $sFilter, $iFlag) $FileList = _FileListToArray($sPath, $sFilter, $iFlag) If @Error=1 Then MsgBox (0,"","No Folders Found.") Exit EndIf If @Error=4 Then MsgBox (0,"","No Files Found.") Exit EndIf Return $FileList[0] EndFunc Edited December 13, 2011 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Clark Posted December 13, 2011 Share Posted December 13, 2011 (edited) I notice that there is no slash before the filename you are searching in the second line. edit: that was to the OP, as J1 was too quick for me. Edited December 13, 2011 by Clark Link to comment Share on other sites More sharing options...
Ram Posted December 13, 2011 Author Share Posted December 13, 2011 Hey John...I tried your code...It endup giving me:D:TempFiles.au3 (31) : ==> Variable used without being declared.:$FileList = _FileListToArray($sPath, $sFilter, $iPath)$FileList = _FileListToArray($sPath, $sFilter, ^ ERRORI think there is something missing which I am not sure. I thought getting number of files in a folder is easy and straight forward. Looks like it is not. Can you please help me out!Thanks! Link to comment Share on other sites More sharing options...
Ram Posted December 13, 2011 Author Share Posted December 13, 2011 (edited) Figured it out. $iPath was not required instead - 0 (for the flag..) Thanks! Edited December 13, 2011 by Ram Link to comment Share on other sites More sharing options...
Ram Posted December 13, 2011 Author Share Posted December 13, 2011 (edited) Hey! Is it possible to specify multiple extensions - so that it can calculate both extension and give me the number of files in the folder? say for example - I have 10 pdf files and 20 jpg files. I would like to get the number of files as 30. Awaiting your response! Thanks! Edited December 13, 2011 by Ram Link to comment Share on other sites More sharing options...
Mikeman27294 Posted December 13, 2011 Share Posted December 13, 2011 No, I think $iPath should be the same as the first parameter passed into _NumFiles. In this case, I am sure $iPath should be @ScriptDir. Link to comment Share on other sites More sharing options...
Ram Posted December 13, 2011 Author Share Posted December 13, 2011 No, I think $iPath should be the same as the first parameter passed into _NumFiles. In this case, I am sure $iPath should be @ScriptDir.If I put iPath - it didn't work - I removed iPath and started working. Link to comment Share on other sites More sharing options...
JohnOne Posted December 13, 2011 Share Posted December 13, 2011 (edited) Sorry: $iPath should be $iFlag EDIT: I should really have tested before posting. Edited December 13, 2011 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 13, 2011 Moderators Share Posted December 13, 2011 Ram,say for example - I have 10 pdf files and 20 jpg files. I would like to get the number of files as 30Look at the RecFileListToArray UDF in my sig - it allows you to search for multiple extensions. 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...
Ram Posted December 14, 2011 Author Share Posted December 14, 2011 Ram,Look at the RecFileListToArray UDF in my sig - it allows you to search for multiple extensions. M23Yeah. I got to see that..from help document! Thanks a lot for your help! Johnone and M23.. 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