How to loop through files in a directory?

Hey, guys!

I’ve an issue… how could I loop through a directory and execute certain actions in the files I found with a certain pattern?

I thought something like:
For each item (with pattern) in directory (C:/…/…)
Do this regex extraction…

Best Regards

@Caio_Dultra You can use this Statement :
Directory.GetFiles(“YourFolderPath”) in an Assign Statement.

Assign this to an Array of String Variable.

Then you can Loop through the Files using a For Each

5 Likes

Great, I’ll try it. Thank you!

1 Like

Do you know some object that allows my user to select in which folder this action would be executed? Something like Select Folder activity where my directory path in the assign activity above could be dinamic?

@Caio_Dultra I did not get your Question? Can you please Elaborate? :sweat_smile:

1 Like

Sorry, let me rewrite it.

Do you know Select Folder Activity? It allows me to choose a directory for a certain action, right?

I’ve a sequence of Regex Matches extractions to be executed in each file reached in the instruction you just gave me above. But I’d like to let the user to choose the directory for the actions to be executed.

Is it clearer now?

Best Regards,

@Caio_Dultra Yes, I guess the Steps Should work along with the Select Folder Activity. What is the Problem you have faced? Select Folder Activity gives the Output Argument as Folder Path, So It shouldn’t be a Problem

I could just assign it as a dinamic variable and put it inside like “Directory.GetFiles(strPathVar)”, right?

@Caio_Dultra Yes of Course. You can always give a Try :sweat_smile:

1 Like

Of course not, but to try it I had to know how to loop through files in the directory. I’ll try it and return to you right after. Thank you! :slight_smile:

1 Like

@Caio_Dultra Sure. Happy Exploring :smile:

1 Like

@supermanPunch

How could I use For Each Activity to read only the .txt files in this directory?

I’ve just tried and worked flawless. Thank you!

You’ll want to start googling stuff like this because that is how you will ultimately become most resourceful and self-sufficient.

If you Googled Directory.GetFiles text files, for example, you would very quickly stumble across references like Directory.GetFiles(path, “*.txt”)

I would also encourage you to enable the ability to view file extensions in your windows. Makes it easier to see the full file name.

3 Likes

Thank you, Bryan. It’s just cause I’m stucked on it and I’ve no ideia of what should I do…

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.