Get Files Methods in UiPath

Hi All,

I am trying to get the files saved in a mapped Sharepoint with file date Current Date minus 1.

When I try to test it, the bot won’t find the Z drive. I tried to use the whole address of the drive, but still wont work. Any chance of help?

in the directory.get files you have to give the path of directory only.
If you want to filter certain files from that directory only you can search with specific patterns.

Hello,

I tried like this Directory.GetFiles(“Z:”) but error says “Could not find part of the path”

Is there something wrong with this?

image

I am trying to filter the Z drive with files that are saved as current date minus 1. Please help. Thankss

Hi @redbee,

You are using right method with just a mistake as i have seen this wil work fine for you:

directory.GetFiles(Config(“Z:”+CurrentDateMinusOne,"*.xlsx")

Hope it will work for you, If anything please feel free to ask me!!
Cheers @redbee

What does the “Config” do? Should I update it in the config file?

2 Likes

can you provide with a sample file name ?
datetime functions would give dates with / which is not allowed so before using directory.get files some string.replace might be required.

e.g i did for file name as 10-01-2020.xlsx

assign stringfilename=datetime.Now.AddDays(-1).ToString(“dd/MM/yyyy”).Replace("/","-")

assign filestoprocess(array of string)= Directory.GetFiles("C:\Users\sourav.anand\Desktop","*"+stringfilename+"*.xlsx")

2 Likes

Sorry!! @redbee
Typing error!

Use below text insteed of it:

image

If any issue let me know.
Thanks!!

@redbee
yes when you are using date to string use this:
CurrentDate.ToString(“dd-mm-yyyy”)

2 Likes

Hi,

This is the path of the network drive: TestFolder_Current (\test\rpa) (Z:)

Inside it, there are excel files. I need to get the files which has file date (current date -1). The file name has format of “Test20200112” (word “test” in the file name is fixed but the date changes)

you can make changes in this according to your filename.

How can I replace if the date format is YYYYmmdd?

I am getting an error message “For Each: The given path’s format is not supported.”. Was it because of the dare format?

datetime.Now.AddDays(-1).ToString(“yyyyMMdd”)

No need for replace in your case.

1 Like

One question, based on the code above, how can I get the filename that starts with the word “Test”? The file format is Test_20200112. If I run based on above, the bot can only read the 20200112. The bot should read the full file name “Test_20200112” so it can read the excel file saved. Does that make sense?

Directory.GetFiles("C:\Users\sourav.anand\Desktop","*Test_"+stringfilename+"*.xlsx")
1 Like

It worked now. Thanks a lot :slight_smile:

2 Likes

@Sourav_Anand, sorry follow up :frowning:

Suddenly, this message pops up

image

Hi @ParasTripathi - can you also look at my issue? :frowning:

@redbee please share your procees.xaml?

_Test.xaml (12.1 KB)

Hi. Please see attached.