Read txt file by extension?

I’m creating a robot that uses “read text file” to read a directory every day with a txt file, but the txt file I change the name, how do I make it read the txt by the file extension?

HI @Rodrigo_Buch

How about this expression?

Directory.GetFiles(Environment.CurrentDirectory+"\Input\","*.txt")(0)

It will get the first text file only from the folder.

image

If you need to get all the text file from the folder

Use For each activity

Directory.GetFiles(Environment.CurrentDirectory+"\Input\","*.txt")

image

Regards
Gokul

@Gokul001
the following error is occurring:

Read Text File: The syntax for the file name, directory name, or volume label is incorrect. : ‘C:\Users\pinhem2\OneDrive - Medtronic PLC\UiPath\ProcessaDOcNumC:\Users\pinhem2\OneDrive - Medtronic PLC\Desktop\PDF Files’

I did it as follows:
Directory.GetFiles(Environment.CurrentDirectory+“C:\Users\pinhem2\OneDrive - Medtronic PLC\Desktop\Arquivos PDF",”*.TXT")(0)

1 Like

Try this:

Directory.GetFiles("C:\Users\pinhem2\OneDrive - Medtronic PLC\Desktop\Arquivos PDF\","*.TXT")(0)

You don’t need CurrentDirectory if you provide full folder path

Hi @Rodrigo_Buch,

What about below code

pass your input path via variable like below

InputPath (String)= “C:\Users\pinhem2\OneDrive - Medtronic PLC\Desktop\Arquivos PDF\"

Directory.GetFiles(InputPath,“*.TXT”)(0)

Thanks,

@Konrad_Mierzwa

hi it worked that way thanks!

It is the Project Location. For example i have provided this @Rodrigo_Buch

Regards
Gokul

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