Jump to content

Recommended Posts

Posted (edited)

Hi all,

I have a folder with many files. I use a stringregexp to test and if the filename is OK I continue.

My 1st problem is here. The regexp does not take into account the beginning of the file name. The good file names are "C05-1702.TXT", "C08-0902.TXT", "Z1-1402.TXT" but not "Done_Z1-1402.TXT", "E4-1402.TXT"

$s_File = "Done_C08-14022023.TXT"

$Regex = StringRegExp($s_File, "(?i)[CZ]{1}\d+\-\d+\.txt", 0)
;~ ConsoleWrite(@extended & @LF)
If @error Then
    ConsoleWrite("ERROR" & @LF)
EndIf
If $Regex = 1 Then
    ConsoleWrite("OK" & @LF)
Else
    ConsoleWrite("NOK" & @LF)
EndIf

After this verification, if the name file is OK I execute the code, or else I continue with the next file in the folder :

ReadFile()
Func ReadFile()
    $s_Folder = @DesktopDir & "\Prog\Automat counting\"
    Local $a_Files = _FileListToArray($s_Folder, "*.txt", 1) ; C08-0902.TXT

    For $i = 1 To UBound($a_Files) -1
        ConsoleWrite("$a_Files[$i] :" & $a_Files[$i] & @LF)
        $b_Validation = StringRegExp($a_Files[$i], "(?i)[CZ]{1}\d+\-\d+\.txt", 0)
        If $b_Validation <> 1 Then ContinueLoop

        ; My code

    Next
EndFunc

Thank you

Edited by jerem488

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

  • Developers
  • Solution
Posted
12 minutes ago, jerem488 said:

but not "Done_Z1-1402.TXT", "E4-1402.TXT"

Just add a ^ to the regex: "(?i)^[CZ]{1}\d+\-\d+\.txt" so it will have to start with C or Z

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

Hi @jerem488,

the return value of StringRegEx (for flag = 0) is 1 (match) or 0 (no match), so please try this instead with the suggestion of @Jos above

If $b_Validation Then
    ContinueLoop
EndIf

; Or

If Not $b_Validation Then
    ContinueLoop
EndIf

Best regards
Sven

Edited by SOLVE-SMART

==> AutoIt related: 🔗 Organization AutoIt Community🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet🔗 autoit-webdriver-boilerplate

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Posted

I'm sorry I really don't have a head! But I've been thinking! I'm used to this language

 

Thanks you guys

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Posted

There is a very nice tool to learn and use RegEx, At the vendors home page there is also really nice stuff to read up.

 

https://www.regexbuddy.com/ 

 

Not freeware, but valuable, I use it almost every day 😉

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Posted

Also free and very valuable is RegExp which allows step-by-step debugging, among other niceties.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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
×
×
  • Create New...