File path

How to get file location from its file name.
Thanks in advance

1 Like

Hi @guptasweb

To get the files try with

Directory.GetFiles("Your folder path")

To get all the files in the subfolder

Directory.GetFiles(Environment.CurrentDirectory+"\Input\Banking Files\","*.*",SearchOption.AllDirectories)

Get File count

Directory.GetFiles(Environment.CurrentDirectory+"\Input\","*.xlsx").Count

Get File Name

Path.GetFileName("Your folderpath")

Get Filename without Extension

Path.GetFileNameWithoutExtension("Your folderpath")

Get all Directories from the folder

Directory.GetDirectories("yourFolderPath","*.*",SearchOption.AllDirectories)

Regards
Gokul

I want the location of a file not the file name i.e path

Check it out @guptasweb

Regards
Gokul

Hello @guptasweb ,

I tend to believe that Path.GetDirectoryName is the method you are looking for. It returns the directory information for the specified path.

For more details, please refer to https://learn.microsoft.com/en-us/dotnet/api/system.io.path.getdirectoryname?view=net-6.0

Best regards,
Marius

1 Like

Hi
As I dont have path so what should I write after path.GetDirectoryName ?

Hi @guptasweb ,

In your case, what is the data you are aware of? What do you know?

Marius

I have only file name

@guptasweb

How do you manage to get the filename? Are you using some method? a loop somewhere?

Best regards,
Marius

@guptasweb
https://www.google.com/amp/s/www.wikihow.com/Find-a-File%2527s-Path-on-Windows%3Famp=1

These are the methods you can implement in UiPath. But there is no specific activity to get filepath through name

That code developed by my colleague I want to do some changes and, in that code, I’m facing such issue i.e.it did not find a file when it ran, and he did not remember the location.

@guptasweb ,

What kind of filepath do you have within your project? Are you using absolute file path? Could you please share a print screen of the sequence you are trying to fix it?

Please refer to this article https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats to know about what I’m talking about.

Best regards,
Marius