Listing file names in datatable

hello, im newbie in UiPath, nice to meet everyone :slight_smile:

How can I create an automation that:

  1. Gets all the file names and/or filepaths
  2. List them in datatable
  3. Move the files in another folder but if the file ends with a number (ex. filename1.txt) it will be excluded

I have some clue on what to use but when i start to implement them; like using getfileinfox, regex, foreach and movefile but when I start to implement the activities, im getting an error. Please help. thank you

Hi @Ryle

  1. Assign Activity - Get File Paths:

    • Create a variable filePaths of type System.String[].
    • Use the “Assign” activity to set filePaths to Directory.GetFiles("yourFolderPath").
  2. Build Data Table:

    • Use the “Build Data Table” activity to create a DataTable named dtFiles with columns “FileName” and “FilePath.”
  3. For Each Activity:

    • Use a “For Each” activity to iterate through filePaths.
  4. If Activity (Inside For Each):

    • Use an “If” activity inside the loop.
    • Condition: Not System.Text.RegularExpressions.Regex.IsMatch(Path.GetFileNameWithoutExtension(item.ToString), ".*\d$")
      (This condition checks if the file name without extension doesn’t end with a number.)
  5. Then (Inside If):

    • Add a “Add Data Row” activity.
    • In the properties of the “Add Data Row” activity:
      • DataTable: dtFiles
      • ArrayRow: {Path.GetFileName(item.ToString), item.ToString}
  6. Else (Inside If):

    • Use the “Log Message” activity to log that the file was excluded.
  7. Move File Activity (Inside For Each):

    • After the “If” activity (outside of the “Then” and “Else” branches), use the “Move File” activity to move the files to the desired folder.
  8. End For Each:

    • Close the “For Each” loop.
  9. Finalize the Workflow:

    • Add any necessary error handling, logging, or cleanup steps.

Make sure to replace “yourFolderPath” with the actual folder path you want to work with.

Hope it helps

You don’t need to put them into a datatable. Just use the For Each File activity.

  • For Each File
    ** If NOT IsNumeric(Right(Replace(CurrentFile.Name,CurrentFile.Extension,“”),1))
    *** Move file

hello, thanks for the answer. i need some clarification in “not” condition, unfortunately, its not in the option; I assume the condition is “is false” or “not equal to?” thanks
111111

You can type directly as

Not System.Text.RegularExpressions.Regex.IsMatch(Path.GetFileNameWithoutExtension(item.ToString), ".*\d$")

Regards

You don’t need to do all that. It’s very simple with just a few activities.

  • For Each File
    ** If NOT IsNumeric(Right(Replace(CurrentFile.Name,CurrentFile.Extension,“”),1))
    *** Move file

hello, also thanks for the answer, I need the data table coz i need to have a record of the files i need to move

Then add them to a list inside the For Each File activity.

@Parvathy
Hello, regarding this one “{Path.GetFileName(item.ToString), item.ToString}”
The item mentioned there is the item in foreach right? if my variable is currentItem, then it’ll be {Path.GetFileName(currentItem.ToString), currentItem.ToString}?
asdasd

Also this one, when running the file, this error occurs
123

Yes @Ryle
It will be currentItem.ToString
Regards