Need help to get the file names from the folder. I am downloading multiple files in certain folder as 001,002,003…etc
So, I want to get the file name for each file downloaded. I tried using “Directory.GetFiles(path)(0)” for this I am getting the first file name as complete path “C:\Users\Downloads\001.pdf”.
But I am looking to capture only the file name like 001,002,003
Please help me here,
Thanks in advance
@NikhilRPA, You are on the right track.
The only thing you need now is to use the
Path.GetFileNameWithoutExtension(item.ToString) to get only the filename and if you want to include the extension too, then replace:
This might be confusing, so i made a small sample workflow for you, please let me know if it helps:
Main.xaml (6.0 KB)
Hi Thanks for the help I tried using to assign the below to particular variable in for each loop “Path.GetFileNameWithoutExtension(item.ToString)”
I am getting an error it is not allowing me to assign to the string variable and I downloaded your Xaml file. Please find the below error
@NikhilRPA, close your studio, delete the Project.Json that belongs to the .xaml file i sent you and open it again.
This is what it looks like, let me know if you experience further issues.
Hi, This is what error I am getting. I have created readfiles variable as an array of string
and FileName1 as a string property
and I deleted project.json file which related to XAML and even though I am not able to see the rest of the code and I am using 20.4 uipath version
This is a bit strange , can you please ty this:
Yes I tried, but getting the sane error
@NikhilRPA, Please send me your file.
@NikhilRPA, Be careful with your naming conventions man, avoid using names like “path” to name your variables, path is a keyword in the .NET library, that is what’s causing confusion.
I renamed your path variable to FilePath and it worked.
Test1.xaml (9.3 KB)
@SenzoD sorry my bad and It worked for me too. This was really helpful and Thanks
@NikhilRPA, always a nice learning experience, glad i could help
Hi need some more help on the same thing. So I want only the first file name instead of all the file names in the folder.
Can you help me?
@NikhilRPA, I’m not sure if i understand you correctly,
If you want the name of the first file you can either delete the for each and just use an assign activity, pass in the array index 0.
Or insert an if to check and only get the name of the first file.
See example: Test1.xaml (10.3 KB)
This is what I need to pass it on the assign activity
Yeah so, it should be like:
This works and Thanks you
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.