Checking if a file in the folder

Hi everyone
I’m trying to check if a specific file is existing inside a specific folder.
I’m getting the file and the folder from the user,
image

and in the if after I wrote “CheckFile.length>0”
and if so continue… else “Throw”…
Please help

  1. use IO to get files from Folder (Sent from User)
  2. run for each loop on output
    2 a. check if file(shared by User) exists in folder
  3. End
1 Like

thanks for the help
but at the end I used:
Check = “Directory.GetFiles(path).where(function(n)) n.contains(name)).count”
and then I checked if its bigger than 0

hi @dlichtenstadt,

string files = System.IO.Directory.GetFiles(path, “filename.*”);
if (files.Length > 0)
{
//file exist
}

Refer to this for more info :


Mukesh

1 Like

thanks
but i do want the extension, because when I doing a “read range” I need the extension.
if the extension is not in the name, hidden, I need to know how to get it so my “read range” won’t collapse

@dlichtenstadt Hello, please find a attached . I think this is exactly what you are looking for . Because you are expecting a workbook with that particular name we should be checking for all types of workbook extension , i…e csv, xlsx, xls & xlsb. This sequences checks for all instances and gets the actual file path before eventually reading it , and if the file is not found it throws an exception CheckFile.zip (27.4 KB)

hi @dlichtenstadt ,

Step 1 : We Check if the File name mentioned in the strExcelfileName is avaialble at the path in_Inputfolder and get the output in strSourceExcelPath

Step 2 : In If statement - We verify if the File is available or not as shown below -

Step 3 : If Condition is True - That means the File is not available.

step 4 : In the else part of if condition - Use a Read Range and Pass the strSourceExcelPath


Mukesh

I checked your program
it worked on a file with the extension “csv”, but if I’m giving the process a file of “xls” it won’t work, and give me an error.
I added the extension “xls” but how do I know that I covered all the options?
didn’t found anywhere what are the options that Uipath is covering

Hello @dlichtenstadt ,

Apologies, I forgot to add the extension for .xls

CheckFile (2).zip (27.1 KB)

please find attached again

1 Like

U didnt have to do I added it myself
the question is - is there any other extension that I can get for excel files that I didnt checked?
because if so - I’m screwed…

1 Like

hello , hahaha, don’t worry , you are okay for now… even if an excel is created with an older version of microsoft excel its going to come as .xls.
However you can go ahead and include .xlsm,.xltx,.xlam and .xlt, but these are rare . I have never seen them been used in my life.

Option 2:
But we could further optimize the workflow to say “okay if you cant find myfile with the specific extensions i supplied , go ahead to check if myfile exist in that folder with any other type of extension in this world”.

But the issue with this logic here is that if we coincidentally have a file like myfile.doc it would pick it up as a what it is looking for and when it tries to open it with the excel scope it would throw an error because the file would actually be of a word format.

I still think our current resolution is the best.

Cheers.

Thank u very much
I understand what u said, we will leave it like this.
the Q is do I need to change the way I open it? with “read range” of “workbook” or “excel scope”?

@dlichtenstadt you are welcome . its okay with an excel application scope . the read csv opens .csv and the excel application scope with a read range would open any other format

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.