这是一行:
string t = Path.GetDirectoryName(file1);
Run Code Online (Sandbox Code Playgroud)
结果是:
C:\\Users\\bout0_000\\AppData\\Local\\Extracting_Frames\\Extracting_Frames\\dat file\\converted.avi\\histogramValues.dat
Run Code Online (Sandbox Code Playgroud)
我希望它只包含:converted.avi.
PS:converted.avi不是文件名,而是路径名.我想得到路径的最后一部分是没有文件名的最后一个子目录.
如果converted.avi是文件名,那么使用它
string t = Path.GetFileName(file1);
Run Code Online (Sandbox Code Playgroud)
文档:http://msdn.microsoft.com/en-gb/library/system.io.path.getfilename.aspx
但是,如果这是目录的名称,您可以从已有结果的最后一个反斜杠后提取所有内容.例如
var path = Path.GetDirectoryName(fileName);
var parentFolder = path.Substring(path.LastIndexOf('\\')+1);
Run Code Online (Sandbox Code Playgroud)
实例:http://rextester.com/RYPMI91227
| 归档时间: |
|
| 查看次数: |
558 次 |
| 最近记录: |