Check files are available in folder if any file is not available in folder then it will send email with the missing file name attached in it

Hi Team

I have a folder, and within that folder is a subfolder, and within that subfolder is another subfolder, and within those folders and subfolders are files.

Ex - main folder
Subfolder 1
Subfolder 2
Subfolder 3

First, I must verify that all six files are present in those directories. If any of the files are missing, I must identify the missing file name and notify the team that this particular file is not present in this folder.

Name of files is - File 1 , File 2 , File 3 , File 4 , File 5 , File 6

@Shivam_Rana

You can use for each file in folder activity …it has an option to include sub folders as well

and you can use filter to check for your required files

image

Or you can use Directory.GetFiles("MainFolder","FileFilterTocheckeachfile",SearchOption.AllDirectories)

on the result you can do a .count to check if files are present or not

cheers

1 Like

Hi @Shivam_Rana

Try this-

  1. Set a variable to hold the path of the main folder you want to search within. For example, folderPath = "C:\MainFolder".
  2. Create an array or list variable to store the names of the files you want to verify. For example, fileNames = {"File1.txt", "File2.txt", "File3.txt", "File4.txt", "File5.txt", "File6.txt"}.
  3. Utilize the Directory.GetFiles method to retrieve a list of all file paths within the main folder and its subfolders. Use the search option SearchOption.AllDirectories to include all subfolders recursively.
  4. Iterate over each file name in the fileNames variable.
  5. For each file name, use the File.Exists method to check if the file exists within the folder structure. Provide the full path to the file using Path.Combine(folderPath, fileName).
  6. If a file is missing, log the missing file name and notify the team. You can use the Log Message activity or send an email with the missing file names.

Thanks!!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.