FileInfo.DirectoryName プロパティ

定義

ディレクトリの絶対パスを表す文字列を取得します。Gets a string representing the directory's full path.

public:
 property System::String ^ DirectoryName { System::String ^ get(); };
public string DirectoryName { get; }
public string? DirectoryName { get; }
member this.DirectoryName : string
Public ReadOnly Property DirectoryName As String

プロパティ値

String

ディレクトリの絶対パスを表す文字列。A string representing the directory's full path.

例外

ディレクトリ名に null が渡されました。null was passed in for the directory name.

完全修飾パス名がシステム定義の最大長を超えています。The fully qualified path name exceeds the system-defined maximum length.

呼び出し元に、必要なアクセス許可がありません。The caller does not have the required permission.

次の例では、指定されたファイルの完全なパスを取得します。The following example retrieves the full path of the specified file.

String^ fileName = "C:\\TMP\\log.txt";
FileInfo^ fileInfo = gcnew FileInfo( fileName );
if (  !fileInfo->Exists )
{
   return;
}

Console::WriteLine( " {0} has a directoryName of {1}",
   fileName, fileInfo->DirectoryName );
string   fileName = @"C:\TMP\log.txt";
FileInfo fileInfo = new FileInfo(fileName);
if (!fileInfo.Exists)
{
    return;
}

Console.WriteLine("{0} has a directoryName of {1}",
    fileName, fileInfo.DirectoryName);
/* This code produces output similar to the following,
 * though actual results may vary by machine:
 *
 * C:\TMP\log.txt has a directory name of C:\TMP
 */
Dim fileName As String = "C:\TMP\log.txt"
Dim fileInfo As New FileInfo(fileName)
If Not fileInfo.Exists Then
    Return
End If

Console.WriteLine("{0} has a directoryName of {1}", fileName, fileInfo.DirectoryName)
' This code produces output similar to the following,
' though actual results may vary by machine:
' 
' C:\TMP\log.txt has a directory name of C:\TMP

注釈

親ディレクトリをオブジェクトとして取得するには、 DirectoryInfo プロパティを使用し Directory ます。To get the parent directory as a DirectoryInfo object, use the Directory property.

最初にを呼び出すと、はを FileInfo 呼び出し、 Refresh ファイルに関する情報をキャッシュします。When first called, FileInfo calls Refresh and caches information about the file. その後の呼び出しでは、 Refresh を呼び出して情報の最新のコピーを取得する必要があります。On subsequent calls, you must call Refresh to get the latest copy of the information.

適用対象