Sign in to follow this  
Followers 0
Khab

Opening files with a RegEx for the name

1 post in this topic

#1 ·  Posted (edited)

EDIT: Updated, ok now it does call my function. Never mind :)

Hi all,

I am trying to make a script which will open all files (they are CSV's) in a given folder, whose filename matches a specific string format, and then perform a function on those files. The only issue I'm having, is I can't seem to get it to iterate through the relevant files.

So, for example, there may be in the folder the files

USERS_090509043511.CSV

USERS_100509043119.CSV

USERS_110509043344.CSV

And I want to open each file, and then perform the operations. I can make it work if I specify the filenames - but these are generated by the system based on the timestamp when the file is created. There are other .CSV files in the folder that I do not wish to touch.

Here is what I've tried:

$fileRegEx = FileFindFirstFile("USERS_*.CSV")
If $fileRegEx = -1 Then
 Exit
EndIf

While 1
 $file = FileFindNextFile($fileRegEx)
 If @error = 1 Then
  ExitLoop
 EndIf
 MyFunction($file)
WEnd

But it never seems to actually run MyFunction() - I've tried setting that function to do nothing but open a message box saying it ran in order to test if it's being called, and even that doesn't happen. So, I believe I am doing something wrong with this section of code. I've checked the online documentation and tried a forum search, but still can't seem to see where I'm going wrong ... Any help would be much appreciated.

EDIT: Updated, ok now it does call my function. Never mind :party:

Edited by Khab

Share this post


Link to post
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
Sign in to follow this  
Followers 0