I have 3 files in a folder e.g A.xlsx,B.csv,C.xls and i want to check that all Files are exist? if yes then only proceed…please help
Try this:
vbFilesExist = (From file In Directory.GetFiles("YourFolderPath") Where {"A.xlsx", "B.csv", "C.xls"}.Contains(Path.GetFileName(file)) Select file).Count = 3
vbFilesExist
is of DataType System.Boolean.
→ Use an If condition
If
vbFilesExists
Then
\\ Do required process
Else
\\ Do required process
End If
Hope it helps
Hi @Hemant_Deshmukh
Test the following project!
BlankProcess.zip (3.2 KB)
Cheers!
You can try this
Directory.GetFiles("FolderPath").ToArray.all(Function(a) arr_str.Contains(path.GetExtension(a.ToString)))
arr_str={“.xlsx”,“.csv”,“.xls”}
Assign Activity
arrCheckFiles | DataType: String Array =
{"A.xlsx","B.csv","C.xls"}
Assign Activity:
arrFileNames =
new DirectoryInfo("YourFolderPath").GetFiles().Select(Function (x) x.Name).toArray
We can check by
arrCheckFiles.All(Function (x) arrFileNames.Contains(x))
Hi @Hemant_Deshmukh ,
you can use linq in assign activity to check if these 3 files exist in a folder. add the linq result to a boolean variable.
Directory.GetFiles(“C:\Users\sneha.vijayan\Documents\UiPath\demo2\demo”).Count(Function(file) Path.GetFileName(file) = “a.xlsx” OrElse Path.GetFileName(file) = “B.csv” OrElse Path.GetFileName(file) = “c.xls”) = 3
thank you so much its working…can you add one more condition for all files-LastWriteTime.Date = Now.Date) ?
Do you want it in same condition if yes below is the condition:
vbFilesExist = (From file In Directory.GetFiles("YourFolderPath") Where {"A.xlsx", "B.csv", "C.xls"}.Contains(Path.GetFileName(file)) AndAlso File.GetLastWriteTime(file).Date = DateTime.Now.Date Select file).Count = 3
Regards
(From fi in new DirectoryInfo("YourFolderPath").GetFiles()
Where fi.LastWriteTime.Date = now.Date
Select f = fi.Name).toArray
and we can check as done above
I am getting below error.
"getlastwritetime"is not memeber of string
Try this:
vbFilesExist = (From file In Directory.GetFiles("YourFolderPath") Where {"A.xlsx", "B.csv", "C.xls"}.Contains(Path.GetFileName(file)) AndAlso System.IO.File.GetLastWriteTime(file).Date = DateTime.Now.Date Select file).Count = 3
Regards
[BC30512: Option Strict On disallows implicit conversions from ‘Boolean’ to ‘Integer’. The selected value is incompatible with the property typ]
our vbFilesExist is boolean veriable…
Do you want both in seperate conditions or in one condition. THe condition which i have given, the output variable is of DataType System.Boolean.
Regards
sorry that solution was correct …thank you
You’re welcome @Hemant_Deshmukh
Happy Automation!!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.