ExisitFileCheck

Hi, I am checking the files exits in the folder or not. where there is a files present in the folder it’s checking fine when there is no files then it’s thrown an error.
image

@Palaniyappan @lakshman

1 Like

Hi @balkishan

In your assign, Director.GetFiles will actually produce you a string array with all the files in the folder you have specified.

If you want to check whether there is a specific file or not in the directory, use the File Exists activity. There you can give the file path and check there its available or not. It will return a boolean value depending on the result.

1 Like

Hi @Lahiru.Fernando Thanks for your quick response.
Previously I created the String variable only and then check the files exist or not.
I am not sure if I give the direct path will it check or not as it’s accepting the String variable only.
image

I directly store the file path in a variable Path and pass directly to the Activity but it doesn’t work as you can see the result it’s showing False as there is a file in the folder.

@balkishan In the Assign Activity You are trying to get list of files in a particular directory, In Path Exists you have to pass the exact file path directly, if your file name changes every time and if you are getting all the files in the directory then first get the Count of the files if the count is greater than 0 then you can do the rest of the process or exit the loop.

1 Like

the file path mentioned in the Path in argument, is that file available in that particular folder?

1 Like

Yes @Lahiru.Fernando file is there in the folder bro.
image

If you see bro I disabled the assign activity. So in the arguments Path I directly give the path of the files. Then pass this variable to the File Check Activity.

@balkishan

The previous screenshot shows the file path that was sent to check
image

Its something starts with hash
However the file you shared here (“InvoiceData”) is a different name. is that correct?

1 Like

This is the Path of the Files bro in the red color you marked.

If I do this way it then also it’s not working

@WhenCutEsh

The Path Exists Activity Accepts String Argument and outputs a Boolean then use an If else to delete the file if exists or do your logic.

1 Like

You have created a List , you need to access each file as an object by using for each loop, then you can check if the file exits or not currently you are passing an array in The Path Exists Activity which is wrong.

1 Like

Okay Okay understood bro, My Bad.

Okay tell me in the case of single file only.
I don’t want to check multiple file.

Yes the GetFiles will search for file in the specified folder
if there is no file in the folder which is been specified in the getfile method as argument
then Directory class wont return any value
so does the FilePath variable
thats why this error occurred stating that object reference is not set to an instane of an object
Cheers @balkishan

1 Like

and we can check with the file present or not with simple PATH EXISTS activity
where we can mention the expression like
Directory.GetFiles(“yourfolderpath”,“yourfilename”)

this will return a boolean value with which we can validate whether its there or not
Cheers @balkishan

So how to handle this.
I need False and True result only.

1 Like

may i know what is mentioned inthe right side of the assign activity wehre FilePath is assigned
Cheers @balkishan

1 Like

Checked this also but not worked.

Directory.GetFiles(Path,“*.xlsx”).OrderByDescending(Function(d) New FileInfo(d).CreationTime)(0).ToString

1 Like

This we need to give in array but the activity accept only String type variable.

1 Like