Validation question: checking files in directory

Ranorex Studio, Spy, Recorder, and Driver.
lightman
Posts: 9
Joined: Tue Jun 01, 2021 1:54 pm

Validation question: checking files in directory

Post by lightman » Wed Dec 01, 2021 8:30 am

Hi everybody!

I want to check the existence of some special files in a directory in the Windows explorer.
Is this possible?

Example:
Open Application: C:\Program Files\test\file1.jar and so on.
Validation: file1.jar exists

Maybe it's possible to create a list of files which will be checked?

Thanks for your help.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7422
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Validation question: checking files in directory

Post by odklizec » Wed Dec 01, 2021 10:59 am

Hi,

In my opinion, the best way to achieve what you want is to use C# code, e.g. File.Exists() method.
https://www.geeksforgeeks.org/file-exis ... -examples/

Eventually, use Directory.GetFiles() method to obtain the list of files and check the existence of certain file via foreach loop...
https://stackoverflow.com/a/58978165

Using Explorer and UI is a waste of time and energy for this particular task ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Elena_v
Posts: 18
Joined: Tue Jun 25, 2019 4:27 pm

Re: Validation question: checking files in directory

Post by Elena_v » Mon Dec 13, 2021 1:18 pm

Code: Select all

using System.IO;

string path = "C:/myfolder/";
if (File.Exists(path)) 
{
    Ranorex.Report.Info(path, "file exists");
}