Cucko
Cucko

Reputation: 193

Get file path and file name from directory - C#

I am trying to get the file path and file name of I file I upload in a folder. I have the paths like so:

string path = Path.Combine(_webHost.ContentRootPath, "Uploads\\ZipFiles\\");
string extractPath = Path.Combine(_webHost.ContentRootPath, "Uploads\\ExtractedFiles\\");

I upload my file in path and I unzip the file in extractPath.

string fullPath = Path.GetFullPath(extractPath);
string fileName = Path.GetFileName(extractPath);

fullPath returns the correct path but fileName is empty. I don't get the file name. I am trying to get something like this

var dbfPath = "C://ExtractedFiles//fileName.jpg"; I was planning on getting the file path in one variable and the file name in another and then concatenate them but I can't get the file name. What's the best way to do this?

Upvotes: 0

Views: 2013

Answers (1)

AnGG
AnGG

Reputation: 831

To get the files in the ExtractedFiles folder :

string[] files = Directory.GetFiles(extractPath)

If your zip have folders inside, and you want to get all the file inside them recursively use :

string[] files = Directory.GetFiles(extractPath, "*.*", SearchOption.AllDirectories)

Upvotes: 1

Related Questions