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.
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.
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.
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.
the file path mentioned in the Path in argument, is that file available in that particular folder?
Yes @Lahiru.Fernando file is there in the folder bro.
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.
The previous screenshot shows the file path that was sent to check
Its something starts with hash
However the file you shared here (“InvoiceData”) is a different name. is that correct?
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
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.
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.
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
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
may i know what is mentioned inthe right side of the assign activity wehre FilePath is assigned
Cheers @balkishan
Checked this also but not worked.
Directory.GetFiles(Path,“*.xlsx”).OrderByDescending(Function(d) New FileInfo(d).CreationTime)(0).ToString
This we need to give in array but the activity accept only String type variable.