使用 Windows API Code PackCommonOpenFileDialog
时,如何在不获取路径信息的情况下检索filename
a file
(如)?mydoc.text
问问题
378 次
2 回答
3
用 C#?
string lcMyPath = GetPathFromSomewhere();
string lcMyFilename = Path.GetFileName(lcMyPath);
//-- C:\myfile.txt -> myfile.txt.
Console.WriteLine(lcMyFilename);
于 2012-10-05T20:55:07.040 回答
1
试试这个:http: //msdn.microsoft.com/en-us/library/system.io.path.getfilename.aspx
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string result;
result = Path.GetFileName(fileName);
Console.WriteLine("GetFileName('{0}') returns '{1}'",
fileName, result);
result = Path.GetFileName(path);
Console.WriteLine("GetFileName('{0}') returns '{1}'",
path, result);
// This code produces output similar to the following:
//
// GetFileName('C:\mydir\myfile.ext') returns 'myfile.ext'
// GetFileName('C:\mydir\') returns ''
于 2012-10-05T20:55:32.850 回答