File drive search

Hello everybody!
I am a beginner in automation with UiPath. I want to search a file drive by first name and last name from an Excel spreadsheet. Does anyone have an approach how I can get started? I am thankful for every help!

1 Like

Hey @degen,

Something like below

Directory.GetDirectories("C:\Users\Nithin Krishna\Downloads\", "*" + FirstNameVar + "*" + LastNameVar + "*").Count

First argument should be your core directory to search & Second should be your search pattern for the directory in your case its firstname & lastname.

Hope this helps.

Feel free to post for any queries.

Thanks :slight_smile:

Hey @Nithinkrishna, thank you for your help.
It works! I thought about extending the automation as follows:

The robot should search for files on a drive (e.g. D:) that contain a first name and last name. PDF files, Excel files, Word files, Access files are to be considered. The found files should be listed in an Excel table. The list contains a consecutive number, the file name and the file path. All found files and the created Excel table should be stored in a folder on the file drive. An e-mail is to be sent that the search has been completed and the files have been stored in drive XY. If no files were found, a negative information is to be sent by e-mail.

Can you assist me to automate this use case?

1 Like

Sure @degen, Why not :slight_smile:

  1. Just replace the function GetDirectories with GetFiles to search for files
  2. Build a data table with two columns - file name & path
  3. Use for-each to iterate the list got from step1
  4. Add data row on every iteration as - {Path.GetFileName(item), Path.GetFullPath(item)}
  5. Send email using mail activity package - Attach a file as well

Hope this helps.

Feel free to post any more queries

Thanks :slight_smile:

@Nithinkrishna it doesn’t work :frowning:

I think it has a failure in the for each row.

Can you check it with the attached file?

Main.xaml (9.0 KB)

Hi @degen,

First check the file is already exists are not the contine.
IF condition - File.Exists("C:\degen\input\"+row("firstname").ToString()+row("LastName").ToString()+".xlsx")


Hi @arivu96,

do you think I should check if there is a file with the first name and last name on the file drive?

So the robot should search for a first name and last name on the whole file drive and not in a single file. I am now so far that the first name and last name is read from an Excel file. Then follows an assignment
file = Directory.GetDirectories(β€œD:”, β€œ" + FirstVar + "” + LastVar + β€œ*”)
file is of the variable type System.String

Afterwards all found files should be listed in a data table with the help of a for each loop and this is the step that does not work yet. Do you have an idea how this could work?

Many greetings

Yes before you try to access the file nees to check the file is exists or not.

Your logic is correct only maybe you made an small mistake or logic need to be correct it.


Hello, I have made progress!
But the search is only for the file name and I want to search for words within the files on a drive. Can someone please help me?