AutoitMike Posted March 1, 2022 Posted March 1, 2022 I have a need to get the sub folders in a path that have an eight digit numbered name, EG: C:\test\sam\mike\00000001 C:\test\sam\mike\00000002 C:\test\sam\mike\00000014 but not C:\test\sam\mike\75123MM _FileListToArray can be set to reurn only folders. How do I set a filter for _FileListToArray to return only eight digit numbers? If StringRegexp is the answer, what would be the parameters? Thanks
ad777 Posted March 1, 2022 Posted March 1, 2022 (edited) @AutoitMike Global $aFileList = _FileListToArray("C:\test\sam\mike\", "*") Global $add[$aFileList[0]] For $i = 1 To $aFileList[0] If StringLen($aFileList[$i]) = 8 And Not $aFileList[$i] = "75123MM" Then $add[$i] &= $aFileList[$i] EndIf Next _ArrayDisplay($add) Edited March 1, 2022 by ad777 none
Guest Posted March 1, 2022 Posted March 1, 2022 (edited) 3 hours ago, AutoitMike said: If StringRegexp is the answer, what would be the parameters? The mention of RegEx in the help on _FileListToArray and _FileListToArrayRec is misleading. The filter you enter is internally converted into a RegEx to speed up the comparison code when searching - but the filter must be of the form indicated in the Help file. Use : #include <Array.au3> #include <File.au3> Local $aFolderList = _FileListToArrayRec("C:\test\sam\mike", "*" , $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_NOPATH) Local $aFolderListNew[0] For $i = 1 To $aFolderList[0] If StringRegExp($aFolderList[$i], '^(\d{8})$', 0) Then _ArrayAdd($aFolderListNew, $aFolderList[$i]) Next _ArrayDisplay($aFolderListNew) ; *** just for display If you need the full path to the folder in the result array ($aFolderListNew) , please use : #include <Array.au3> #include <File.au3> Local $aFolderList = _FileListToArrayRec("C:\test\sam\mike", "*" , $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_FULLPATH ) Local $aFolderListNew[0] For $i = 1 To $aFolderList[0] If StringRegExp(StringRegExpReplace($aFolderList[$i], "^.*\\", ""), '^(\d{8})$', 0) Then _ArrayAdd($aFolderListNew, $aFolderList[$i]) Next _ArrayDisplay($aFolderListNew) ; *** just for display Edited March 1, 2022 by Musashi
Nine Posted March 1, 2022 Posted March 1, 2022 (edited) Another solution would be to use StringIsDigit (see help file) #include <Array.au3> #include <File.au3> Local $aFolderList = _FileListToArrayRec(@ScriptDir, "*" , $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_FULLPATH ) Local $aFolderListNew[0], $sDrive, $sDir, $sFileName, $sExtension For $i = 1 To $aFolderList[0] _PathSplit($aFolderList[$i], $sDrive, $sDir, $sFileName, $sExtension) If StringIsDigit($sFileName) Then _ArrayAdd($aFolderListNew, $aFolderList[$i]) Next _ArrayDisplay($aFolderListNew) ; *** just for display ps. in the case of full path, here another SRE : If StringRegExp($aFolderList[$i], "(?:.*\\)(\d+)$") Then ... pps. note that in both cases I did not check for the exact 8 digits as I felt it was restricting the search for nothing... Edited March 1, 2022 by Nine added code / another SRE “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Guest Posted March 1, 2022 Posted March 1, 2022 (edited) 1 hour ago, Nine said: Another solution would be to use StringIsDigit _PathSplit($aFolderList[$i], $sDrive, $sDir, $sFileName, $sExtension) If StringIsDigit($sFileName) Then _ArrayAdd($aFolderListNew, $aFolderList[$i]) _PathSplit with StringIsDigit is a good realisation as well (and likely easier to read, than a RegEx version, the OP was asking for). Currently, however, folders with more or less than 8 digits are also found this way, but that should be something @AutoitMike can solve himself . EDIT : Oh, I see you've already added that : 1 hour ago, Nine said: pps. note that in both cases I did not check for the exact 8 digits Edited March 1, 2022 by Musashi
AutoitMike Posted March 2, 2022 Author Posted March 2, 2022 Thanks everyone for the help. I figured that a local array needs to be created and used rather than using the function _FileListToArray
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