Create a UiPath workflow that extracts file names from a datatable that do not exist in a folder

How to create a UiPath workflow that extracts file names stored in a data table column that do not exist in a particular folder. I want to check this for a set of folders in one loop and get folder wise log output.

Folder A = 2 files - qq.xyz,ww.xyz
Folder B = 4 files - kk.xyz,dd.xyz,kk.xyz,rr.xyz

File names in data table= qq.xyz,ww.xyz,kk.xyz,dd.xyz,kk.xyz,rr.xyz,jj.xyz,vv.xyz,tt.xyz,pp.xyz

1 Like

@vidyasak,

Below is a UiPath workflow that extracts file names from a DataTable and checks if they do not exist in a folder. This workflow assumes you have a DataTable containing file names in one of its columns.

  1. Drag and drop a “For Each Row” activity onto the workflow canvas.
  2. Set the DataTable you want to loop through in the “For Each Row” activity.
  3. Inside the loop, add an “Assign” activity to get the file name from the current row of the DataTable. Let’s assume the column containing file names is named “FileName”. You can change this according to your DataTable structure.
  • In the “To” field, add a new string variable, say “currentFileName”.
  • In the “Value” field, use the expression row("FileName").ToString().
  1. Add an “If” activity inside the loop to check if the file exists in the folder. You can use the System.IO.File.Exists() method to check if the file exists.
  • Condition: Not System.IO.File.Exists(Path.Combine(folderPath, currentFileName)). Here, folderPath is the path to the folder where you want to check for the file.
  1. If the file does not exist, you can add an activity to perform any action you want, like logging the file name or performing some other operation.

Try this and let us know if you face any error.

Thanks,
Ashok :slight_smile:

1 Like

@vidyasak

  1. Read Range (Read Data Table from Excel or CSV)

  2. For Each (folder in list_of_folders)

    • Assign: filesInFolder = Directory.GetFiles(folder)

    3.1 For Each (row in data_table)
    - If (filesInFolder.Contains(row(“FileName”).ToString))
    - Log Message: "File exists: " + row(“FileName”).ToString
    - Else
    - Log Message: "File does not exist: " + row(“FileName”).ToString
    - End If

    • End For Each (row)

    • Log Message: "Folder processed: " + folder

  • End For Each (folder)

We can produce String Lists with the names and can compare

Working like a charm sir :slight_smile:

Just wanted to add one more step. >> How to add a filter for only .csv?

Got it. added the condition to get only .csv files as and currentFileName.Contains(".csv")

Not System.IO.File.Exists(Path.Combine(folderPath, currentFileName)) and currentFileName.Contains(".csv")

1 Like

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