FileInfo.Directory プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)



親ディレクトリを文字列として取得するには、DirectoryName プロパティを使用します。
その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
Directory.Move DirectoryInfo.MoveTo | |
Directory.Delete DirectoryInfo.Delete | |
CreateDirectory | |
CreateSubdirectory | |
GetDirectories GetDirectories | |
GetFileSystemInfos | |

ファイルを開くか作成して、その絶対パスを判別し、ディレクトリの完全な内容を判別して表示する例を次に示します。
Imports System Imports System.IO Public Class DirectoryTest Public Shared Sub Main() ' Open an existing file, or create a new one. Dim fi As New FileInfo("temp.txt") ' Determine the full path of the file just created. Dim di As DirectoryInfo = fi.Directory ' Figure out what other entries are in that directory. Dim fsi As FileSystemInfo() = di.GetFileSystemInfos() ' Print the names of all the files and subdirectories of that directory. Console.WriteLine("The directory '{0}' contains the following files and directories:", di.FullName) Dim info As FileSystemInfo For Each info In fsi Console.WriteLine(info.Name) Next info End Sub 'Main End Class 'DirectoryTest
using System; using System.IO; public class DirectoryTest { public static void Main() { // Open an existing file, or create a new one. FileInfo fi = new FileInfo("temp.txt"); // Determine the full path of the file just created. DirectoryInfo di = fi.Directory; // Figure out what other entries are in that directory. FileSystemInfo[] fsi = di.GetFileSystemInfos(); Console.WriteLine("The directory '{0}' contains the following files and directories:", di.FullName); // Print the names of all the files and subdirectories of that directory. foreach (FileSystemInfo info in fsi) Console.WriteLine(info.Name); } }
using namespace System; using namespace System::IO; int main() { // Open an existing file, or create a new one. FileInfo^ fi = gcnew FileInfo( "temp.txt" ); // Determine the full path of the file just created. DirectoryInfo^ di = fi->Directory; // Figure out what other entries are in that directory. array<FileSystemInfo^>^fsi = di->GetFileSystemInfos(); Console::WriteLine( "The directory '{0}' contains the following files and directories:", di->FullName ); // Print the names of all the files and subdirectories of that directory. Collections::IEnumerator^ myEnum = fsi->GetEnumerator(); while ( myEnum->MoveNext() ) { FileSystemInfo^ info = safe_cast<FileSystemInfo^>(myEnum->Current); Console::WriteLine( info->Name ); } }
import System.*; import System.IO.*; public class DirectoryTest { public static void main(String[] args) { // Open an existing file, or create a new one. FileInfo fi = new FileInfo("temp.txt"); // Determine the full path of the file just created. DirectoryInfo di = fi.get_Directory(); // Figure out what other entries are in that directory. FileSystemInfo fsi[] = di.GetFileSystemInfos(); Console.WriteLine("The directory '{0}' contains the following files " + " and directories:", di.get_FullName()); // Print the names of all the files and subdirectories of // that directory. for (int iCtr = 0; iCtr < fsi.length; iCtr++) { FileSystemInfo info = (FileSystemInfo)fsi.get_Item(iCtr); Console.WriteLine(info.get_Name()); } } //main } //DirectoryTest
import System; import System.IO; public class DirectoryTest { public static function Main() : void { // Open an existing file, or create a new one. var fi : FileInfo = new FileInfo("temp.txt"); // Determine the full path of the file just created. var di : DirectoryInfo = fi.Directory; // Figure out what other entries are in that directory. var fsi : FileSystemInfo[] = di.GetFileSystemInfos(); Console.WriteLine("The directory '{0}' contains the following files and directories:", di.FullName); // Print the names of all the files and subdirectories of that directory. for (var i : int in fsi) Console.WriteLine(fsi[i].Name); } } DirectoryTest.Main();


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からFileInfo.Directory プロパティを検索する場合は、下記のリンクをクリックしてください。

- FileInfo.Directory プロパティのページへのリンク