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!
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.
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?
Sure @degen, Why not
- Just replace the function GetDirectories with GetFiles to search for files
- Build a data table with two columns - file name & path
- Use for-each to iterate the list got from step1
- Add data row on every iteration as -
- Send email using mail activity package - Attach a file as well
Hope this helps.
Feel free to post any more queries
@Nithinkrishna it doesn’t work
I think it has a failure in the for each row.
Can you check it with the attached file?
Main.xaml (9.0 KB)
First check the file is already exists are not the contine.
IF condition -
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?
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?