Extract the filenames from a folder and save them in Excel or Notepad

To all concerned:

I just want to ask for your assistance on how to get the Filenames of the Files that are saved in the Downloads Folder, in this matter - a pdf file. And after that, these filenames are extracted/copied and should be written and saved in Excel/Notepad. Looks pretty simple but I am having troubling how should get this done.

I am using UiPath Studio 2023.8.0 Community Edition.

Hi @jharmel.carmona ,
You want to get file name
You can use for each file in folder with file *pdf

regards,

Hey @jharmel.carmona ,

Use a ForEach file in the folder activity loop inside the loop youput an assign activity and use he left side field as Path.GetFilename(file) to get the filename only.

Then use a write cell to write it back to Excel

Or you can build a datatable and write all the filenames a once
Please refer below file and add some pdf to the directory
New folder (3).zip (11.0 KB)

Hope it helps you!

Hi @jharmel.carmona
=> Use For Each file in Folder to iterate through each file and give filter by "*.pdf"
=> Use Assign activity and give below condition:

FileName= CurrentFile.Name

The above syntax will retrieve the file name with extension

FileName= CurrentFile.FullName

The above syntax will retrieve the whole file path of the particular file with extension

FileName= Path.GetFileNameWithoutExtension(CurrentFile.ToString)

The above syntax will retrieve the whole file name of the particular file without extension.
=> Use Write Text File to write all the filenames into a Notepad or use Append Line so that every time it gets appended to same file.

Refer the below image for better understanding.

Hope it helps!!

That’s just going to overwrite the forum.txt file every time.

What @jharmel.carmona needs to do is create a datatable DT_Final then…

  • For Each in Directory.GetFiles(folderpath,“*.pdf”)
    ** Add Data Row to add the filename to DT_Final

Then write DT_Final to Excel (Write Range) or CSV (Write CSV)

Hi @Nguyen_Van_Luong1 Where is the portion where it is written in excel or notepad?

@Vikas_M got this error during debugging


how to resolve this MaxLength limit?

@postwick you’re right paul…Data Table is needed. thanks

@Parvathy appreciate if you could send the sequence.xaml file…thanks.

Hi @jharmel.carmona

Sequence13.xaml (7.9 KB)

Use any of the three assign activities syntax as per your requirement.

Regards,

@Parvathy Thanks a lot! It worked.

1 Like

You’re Welcome @jharmel.carmona

Happy Automation
Regards

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