Can I pass(Ignore) the folder if it doesn't contains target excel file?

Hello, all

I need to store target excel file to String value but sometimes there is no target excel file on specific folder. Than I’d like to proceed to next folder without error.
How to configure like below procedure?

  1. Check each folder and store target excel file like below
    image


    Code: Directory.GetFiles(“C:\P00432_FundReport\bank statement\HSBC 001”,"*.xlsx").Where(function(d) Path.GetFileName(d).Contains(“AISTMTPRINT”+DateTime.Now.ToString(“yyyy-MM-dd”)))(0)

  2. If there is no target excel file than pass and check next folder

How to build this logic?

So the target excel file name is different for each folder?? Will there be only one file in each folder or multiple file with the name you are looking for??

You can get the count , if the count is 0 then that folder does not has the target file you are looking for.

1 Like

Hi,

How about the following logic?

If you want to store filename for each folder, perhaps you should use Dictionary<String,String> type.

Regards,

1 Like

Hello!

  1. So the target excel file name is different for each folder?? Will there be only one file in each folder or multiple file with the name you are looking for??

In each folder there are multiple files and there is only 1 file that I targeted, normally filter with today date information .
image

  1. You can get the count , if the count is 0 then that folder does not has the target file you are looking for.

Can I count with String value?
All files are stored like below

Hello~ Thank you for your comment!
Each folder’s file name is different, than should I set this logic for each folder?
Yellow remarked part is different for each folder.

Hi,

Probably you don’t need it because For Each activity iterates each folder in bankstatement folder and dir variable will be set each folder name.

If you want to store file name for each folder, expression in MultiAssign activity will be the following.

dict(System.IO.Path.GetFileName(dir))=ieFile(0)

note: dict is Dictionary<String,String>

Hi @Dorothy_lee

You can also try this way

image

Directory.GetFiles("C:\P00432_FundReport\bank statement", "*.xlsx", searchOption.AllDirectories).Where(Function (f) Path.GetFileName(f).Contains("AISTMTPRINT"+DateTime.Now.ToString("yyyy-MM-dd"))).ToArray

fileArr is an Array of String which will contain the path of targeted excel files.
All the folders inside the “C:\P00432_FundReport\bank statement” will be scanned for the target file, and if they contain the file then it will be added to the array.

1 Like

Hello,
I’ve tried to set flow as you recommended but faced below error message.
Is there any way that I can resolve?

@Dorothy_lee - Please look closely…

You are having typo…it is directories, you are missing the “t”

1 Like

oh.,… Thank you :sweat_smile: