To check if the given file is .csv or .xlsx/.xls and open it based on that

Hey all,

To check if the given file is .csv or .xlsx/.xls and open it based on that.

Thanks in advance!

1 Like

Hey! may be this topic could help you. File extension recognition:
You could use Path.GetExtention(item) =“.xlsx” or Path.GetExtention(item) =“.csv” within a if condition. If true then open it.

1 Like

Informative
Thanks

item must be in the for each loop, Can you help me with that?

Hi
hope these steps would help you resolve this
–use a assign activity likethis
arr_csvfiles = Directory.GetFiles(“yourfolderpath”,“*.csv”)
so this variable will have only file path of all csv files in that specified folder
similarly for xlsx file
arr_xlsxfiles = Directory.GetFiles(“yourfolderpath”,“*.xlsx”)

where both arr_csvfiles and arr_xlsxfiles both are of type array of string
–now use a FOR EACH loop and pass the above variable arr_csvfiles as input and change the type argument as string and inside the loop use READ CSV FILE activity and pass the file path as item.ToString

–then followed by this use another FOR EACH loop and pass the above variable as arr_xlsxfiles as input and inside that loop use EXCEL APPLICATION SCOPE

so this will open the files accrodingly
Cheers @ray_sha

2 Likes

@ray_sha

Try below expression to read all files like .CSV or .xlsx or .xls from specified folder.

      requiredFiles [] = Directory.GetFiles("your folder path","*.*", SearchOption.AllDirectories).Where(Function(j) j.EndsWith(".pdf") Or j.EndsWith(".xls") Or j.EndsWith(".xlsx")).ToArray