ファイルの保存ダイアログがあり、入力したファイル名のみを取得したい。に相当
openfiledialog.SafeFileName;
Save file dialog has no SafeFileName
Property and FileName
returns both filename, path and extension. Pls how do i extract only file name.
ファイルの保存ダイアログがあり、入力したファイル名のみを取得したい。に相当
openfiledialog.SafeFileName;
Save file dialog has no SafeFileName
Property and FileName
returns both filename, path and extension. Pls how do i extract only file name.
拡張子付きのファイル名が必要な場合は、Path.GetFileName()
. 拡張子なしでも必要な場合は、 を使用してPath.GetFileNameWithoutExtension()
ください。
public void Test(string fileName)
{
string path = Path.GetDirectoryName(fileName);
string filename_with_ext = Path.GetFileName(fileName);
string filename_without_ext = Path.GetFileNameWithoutExtension(fileName);
string ext_only = Path.GetExtension(fileName);
}
詳細、特にPath
多くの便利なメソッドを持つクラスについては、MSDN を参照してください。
http://msdn.microsoft.com/en-us/library/System.IO.Path_methods.aspx
http://msdn.microsoft.com/en-us/library/system.io.path.getfilename.aspx
http://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension.aspx