DavidLago Posted March 20, 2017 Posted March 20, 2017 Hello. I need to list only the folders that has a name composed of numbers only. How do I do this? OBS: I just posted the relevant content to the folder. Global $path = "G:\jobs\" For $i = 1 To $aArray[0] Local $search = FileFindFirstFile($path & $aArray[$i] & "\[0-9]" ) I tried with "\*.*" and it returns me the expected result, but the other doesn't.
kylomas Posted March 20, 2017 Posted March 20, 2017 DavidLago, From the Help file... Remarks The search string is not case sensitive. Wildcards: In general, * denotes zero or more characters, and ? denotes zero or one character. If your file search string contains only wildcards (or is "*.*"), then see the example below for the return value! You can use only one wildcard in the filename part or in the extension part i.e. a*.b?. When using a 3-char extension any extension starting with those 3 chars will match, .e.g. "*.log" will match "test.log_1". (not described either in Microsoft documentation). When you have finished searching with the FileFind... functions you must call FileClose() to release the search handle. Directory name are returned according to the wildcards if any. Due to the underlying Windows API used (FindFirstFile), this function actually searches both the long and short filenames when looking for matches. If you get unexepected results then verfiy that it's not the short filename that is being matched. What makes you think you can use a regexp expression? Also, you should not define variables in a loop. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Moderators JLogan3o13 Posted March 20, 2017 Moderators Posted March 20, 2017 It is no secret that regex makes my eyes bleed, so I am sure someone will venture forth to laugh at my attempt, but I would think you'd have to use two arrays: #include <Array.au3> #include <File.au3> Local $aFolders = _FileListToArray(@DesktopDir & "\Testing", "*", $FLTA_FOLDERS) Local $aFinal[0] For $a = 1 To $aFolders[0] If Not StringRegExp($aFolders[$a], "\D") Then _ArrayAdd($aFinal, $aFolders[$a]) Next _ArrayDisplay($aFinal) This works on a directory that looks like so: DavidLago 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
mikell Posted March 20, 2017 Posted March 20, 2017 Using one array is possible For $a = $aFolders[0] to 1 step -1 If StringRegExp($aFolders[$a], "\D") Then _ArrayDelete($aFolders, $a) $aFolders[0] -= 1 EndIf Next _ArrayDisplay($aFolders ) BTW your regex DavidLago 1
iamtheky Posted March 20, 2017 Posted March 20, 2017 Windows 10 you could also just run the bash command ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
KaFu Posted March 20, 2017 Posted March 20, 2017 Here's my approach :)... #include <array.au3> Global $path = @ScriptDir Local $file, $sResult, $search = FileFindFirstFile($path & "\*.*") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If Not @extended Or StringRegExp($file, "\D") Then ContinueLoop $sResult &= $path & "\" & $file & ";" WEnd FileClose($search) If $sResult Then $sResult = StringTrimRight($sResult, 1) $aResult = StringSplit($sResult, ";") _ArrayDisplay($aResult) Else MsgBox(0, "Error", "No Digit only Directories found...") EndIf DavidLago 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Moderators JLogan3o13 Posted March 20, 2017 Moderators Posted March 20, 2017 LOL @mikell I'm great when it's only a single switch "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
DavidLago Posted March 21, 2017 Author Posted March 21, 2017 @JLogan3o13 @KaFu and @mikell thanks a lot. My non-programmer brain sometimes fail to think around this issues. You did help me to get it done the way I needed. Thanks a lot. 15 hours ago, kylomas said: What makes you think you can use a regexp expression? Lack of knowledge or something.
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