[英]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
.我在path
中上传我的文件,然后在extractPath
中解压缩文件。
string fullPath = Path.GetFullPath(extractPath);
string fileName = Path.GetFileName(extractPath);
fullPath
returns the correct path but fileName
is empty. fullPath
返回正确的路径,但fileName
为空。 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?最好的方法是什么?
To get the files in the ExtractedFiles folder:要获取 ExtractedFiles 文件夹中的文件:
string[] files = Directory.GetFiles(extractPath)
If your zip have folders inside, and you want to get all the file inside them recursively use:如果您的 zip 里面有文件夹,并且您想递归地获取其中的所有文件,请使用:
string[] files = Directory.GetFiles(extractPath, "*.*", SearchOption.AllDirectories)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.