How to find the file with exact ID from the folder

i have an excel with list of ID’S .ID Ex: 2142263454,2347752329. Always the length of ID will be 10. After pcking the ID from excel i ahve to pick a file from the folder where the folder contains n number of files.
File format: 2142263454_XXXXXX_439457398573959809

the thing is how to check the file exists or not in the folder based on ID?


@avinashy You will have to get all the files using Directory.Getfiles(“Path”).
Then, loop through the file names and check if that file contains this string,

  1. Use a “Read Range” activity to get the list of ID’s as a Datatable (considering the IDs are different cells in the same column).
  2. Use a “For Each Row” loop. Set the value of the Datatable property to the Datatable variable where you just extracted the IDs from excel in step 1.
  3. Inside this loop, use a “For Each” loop. In the “Values” property, type in Directory.GetFiles(“Path_to_folder”). Here, put the path of the folder containing the files. e.g. “D:\Documents\Folder_of_files” as the argument. Set TypeArgument property to String.
  4. In this loop, use a “If” activity. The condition should be item.Split("_"c)(2) = row.Item(0).ToString.

Now you can do what you need inside the “Then” branch. Happy coding.

Hi @avinashy

Steps to be followed:

  1. Read range - read the excel file
  2. For each row (loop through rows of the datatable)
  3. Inside this loop, assign FilesArr = Directory.GetFiles(Path for the folder, row(“ID”).toString + "* " )
    This will fetch only files starting with this ID.
    If ID is in between the file name, give filter param as "* " + Give row(“ID”).toString + “*”.
  4. Check if the returned string array is not null and has rows - (Not FilesArr is Nothing) AndAlso FilesArr.Length > 0. This confirms that file with that ID is present.

If you can build the path, then use “Path Exists” and select the Path Type to be “File”, the result will be a boolean.

@avinashy Were you able to do this?

If yes, just mark the appropriate reply as solution and close this thread.
If no, let us know your further queries.