ファイルパス

下記のファイルパスが設定されていると仮定して説明します。
string FullPath = "c:\test\hoge\hoge.txt" ;

 //ファイル名の取得
 string Name = System.IO.Path.GetFileName(FullPath);
 ※hoge.txt が取得できます。

 // ディレクトリ名の取得 (最後に'¥¥'は付かない)
 string DirPath =  System.IO.Path.GetDirectoryName(FullPath);
 ※c:\test\hoge が取得できます。

 //拡張子無しのファイル名の取得
 string NameWithoutExt =  System.IO.Path.GetFileNameWithoutExtension(FullPath);
 ※hoge が取得できます。

 //拡張子の取得(1文字目は'.')
 string Ext =  System.IO.Path.GetExtension(FullPath);
 ※.txt が取得できます。

コメント