如何从目录中,而不是整个路径得到的只有文件名 [英] how to get only file names from the directory ,not the entire path
本文介绍了如何从目录中,而不是整个路径得到的只有文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的方法来获取文件名。
i am using below method to get the file names ..
但它返回的整个路径....现在我不想让整个路径。
but it returns the entire path ....now i dont want to get the entire path..
我想只有文件名而不是整个路径...
I want only file names not the entire path...
我怎样才能得到,只有文件名而不是整个路径
how can i get that only file names not the entire path
路径= C:\文档\ DOC \ backup-23444444.zip
path= c:\docs\doc\backup-23444444.zip
string[] filenames = Directory.GetFiles(targetdirectory,"backup-*.zip");
foreach (string filename in filenames)
{ }
会在这任何一个请帮助......
would any one pls help on this.....
非常感谢......
Many thanks...
推荐答案
您可以使用的 GetFileName 方法只提取文件名不带路径:
You could use the GetFileName method to extract only the filename without a path:
string filenameWithoutPath = Path.GetFileName(filename);
这篇关于如何从目录中,而不是整个路径得到的只有文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文