How to do If there is an excel in this file, read excel else don't do anything

Hi. I want to this

If there is an excel file in the folder, read the excel. Else don’t do anything

How can I do that?

1 Like

Hi @sufyant
Use Strarray=Directory.GetFiles(inputfilepath)

use for each item in strarray

in if condition item.ToString.Contains(“.xlsx”)

use read range else give message log message for dont do anything

Thanks
Ashwin S

1 Like

Hi @sufyant

Use Excel application scope activity pass the path of excel file inside use read range activity pass the sheet name and create output data table variable.

Regards,
Kommi Jeevan.

1 Like

I do not understand

Hi @sufyant,

You can use the below statement in an assign to get a list of excel files.

Directory.GetFiles(FolderPath, “.xlsx”).ToList

You can loop for the list and read the excels using Read range activity.

1 Like

hey @sufyant
you can do this
ArrayVariable = Directory.GetFiles(sourcePath, “*.xlsx”)
this will fetch you only Excel File

Cheers

1 Like

HI
hope these steps would help you resolve this
–use a assign activity like this
arr_filepath = Directory.GetFiles(“yourfolderpath”,“*.xlsx”)
where arr_filepath is a variable of type array of strings
this will give us all the xlsx files alone from that folder to this variable arr_filepath

–now use a IF condition like this to validate whether there is any file in the folder or not
arr_filepath.count > 0
if true it will go to THEN part where use FOR EACH activity and pass the variable arr_filepath as input and change the type argument as string
–inside the loop use a EXCEL APPLICATION SCOPE and pass the input as item.ToString and inside that scope use READ RANGE activity and get the output with a variable of type dattable named dt

Cheers @sufyant

1 Like

What is the reason?

1 Like

(“filepath"+”+ilanAdi+" “+tarih+”,“*.xlsx”)

1 Like

Hi @sufyant

i think you missed the +""+

Thanks
Ashwin S

1 Like

May i know what is that ilanAdi and larith
is that a variable
even though if its a variable a folder path or a filepath wont have space in it
probably it would be like this
Directory.GetFiles(“youfolderpath…Candidates\”+“ilanAdi”+“_”+“larith”,“*.xlsx”)
or
Directory.GetFiles(“youfolderpath…Candidates\”+“ilanAdi”+“larith”,“*.xlsx”)

Cheers @sufyant

1 Like

//missed out * here

Directory.GetFiles(FolderPath, “*.xlsx”).ToList

1 Like

yes there are variable

1 Like

then try with either of this, because there would be no space between filename or folder name
but anyhow if its there lets validate this once
use writeline activity and mention this folder path alone
like this
“youfolderpath…Candidates\”+“ilanAdi”+“_”+“larith”
copy that and paste in file explorer so that we can check whether it takes us to the folder or not

Directory.GetFiles(“youfolderpath…Candidates\”+ilanAdi+“_”+larith,“*.xlsx”)
or
Directory.GetFiles(“youfolderpath…Candidates\”+ilanAdi+larith,“*.xlsx”)

Cheers @sufyant

1 Like

@Palaniyappan i’m sorry if im wrong variables declared like this right ??
“+StrVariable+”
tell me if i’m wrong!

2 Likes

Yah modified
you are correct
@Pradeep_Shiv

2 Likes

like that ?

1 Like

Kindly have a view on this
sy.zip (9.7 KB)

Cheers @sufyant

1 Like