Jump to content

FileFindFirstFile with internal Regex


Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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:

AutoIt.PNG

"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!

Link to comment
Share on other sites

Windows 10 you could also just run the bash command :) 

bash_help.png

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...