Dynamic FilePath

I am trying to check if certain html.- files are already saved in my computer folder.

How can I create a sequence for this?
Files have dynamic naming system (string) and they are located in the same folder.

Thanks already!

Hi @Anonymous_Hippo

Welcome to forum

You can use path exist activitiy to check whether a file is existing or not

Hi,

Thanks!

I have tried this, but I cannot succeed in naming the path correctly, as the name changes dynamically. After writing the path to the folder, how should I indicate the file name? If e.g. the name is assigned as string “FileName” how do I write this in the end of the file path?

Hi u can check this way whether the folder contains the HTML files

Directory.GetFiles(folderpath). Where (Function (file) file.Contains(“html”)).Count>0

If the condition is true then there are html files there

Otherwise not

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed:

To get the filename u can use

Path.GetFileName(filepath)

You can use:

Directory.EnumerateFiles("C:\BaseDirectory", "*.html", SearchOption.AllDirectories)

This will search for all *.html files in the BaseDirectory and all sub-folders.

If you know that in the file name some word must contains, you can add it to the pattern as well:
*report*.html.

To just check if the files exists add the .Any() after enumerate the files. This will return a boolean value to you:

If Directory.EnumerateFiles("C:\BaseDirectory", "*.html", SearchOption.AllDirectories).Any() Then
...
End

You can do exactly same thing using .GetFiles instead of .EnumerateFiles but using GetFiles you need to wait all files be populated in memory to perform other operations, if you have to many files this can degrade your bot performance.

1 Like