directory
「directory」とは・「directory」の意味
「directory」とは、日本語で「ディレクトリ」と訳されることが多く、コンピュータのファイルやフォルダを整理するための仕組みである。覚え方としては、英語の「directory」には「指示する」という意味があり、ディレクトリがファイルやフォルダへの道筋を指示していると捉えることができる。また、「directory」の複数形は「directories」となる。「directory」の発音・読み方
「directory」の発音は、/dəréktəri/ であり、日本語では「ディレクトリ」と読むことが一般的である。「directory」の類語
「directory」の類語としては、「folder」や「catalog」が挙げられる。これらの言葉も、コンピュータ上でファイルやフォルダを整理するための仕組みを指す。「directly」と「directory」の違い
「directly」と「directory」は、綴りや発音が似ているため、混同されやすいが、意味は異なる。「directly」は副詞で、「直接に」や「すぐに」という意味があり、一方、「directory」は名詞で、ファイルやフォルダの整理をする仕組みを指す。「directory」を含む用語・関連する用語
「directly」とは
「directly」は副詞で、「直接に」や「すぐに」という意味がある。例えば、「I will contact you directly.(直接あなたに連絡します。)」のように使われる。「Directory C」とは
「Directory C」とは、Windowsオペレーティングシステムにおいて、デフォルトでシステムファイルやプログラムファイルが保存される場所である「Cドライブ」のディレクトリを指す。「directory」の使い方・例文
1. Please create a new directory for the project files.(プロジェクトファイル用の新しいディレクトリを作成してください。) 2. The directory structure should be organized in a logical manner.(ディレクトリ構造は論理的に整理されるべきである。) 3. You can find the file in the ""Documents"" directory.(「Documents」ディレクトリにそのファイルがあります。) 4. The software will automatically create a directory for the installation.(ソフトウェアはインストール用のディレクトリを自動的に作成します。) 5. How can I move this file to another directory?(このファイルを別のディレクトリに移動する方法は?) 6. The directory contains several subdirectories.(そのディレクトリにはいくつかのサブディレクトリが含まれている。) 7. The ""Pictures"" directory stores all the image files.(「Pictures」ディレクトリにはすべての画像ファイルが保存されている。) 8. The directory path should be specified in the configuration file.(ディレクトリパスは設定ファイルで指定されるべきである。) 9. The server's root directory is not accessible to the public.(サーバーのルートディレクトリは一般にはアクセスできない。) 10. The application will scan the specified directory for any changes.(アプリケーションは指定されたディレクトリを変更があるかどうかスキャンします。)ダイレクトリー【directory】
ディレクトリー【directory】
ディレクトリ
ディレクトリとは、コンピュータ上で個々のデータを分類および整理するための、階層構造(ツリー構造)を持った場所の概念である。
オペレーティングシステム(OS)のほとんどは、個々の電子データをファイルという単位で格納することで、一つの単位として扱う。それらのファイルを、ルートと呼ばれるトップレベルの場所から、階層型に分類された下位構造の適切な場所に配置して整理するという考え方を採用している。ディレクトリは、そのような階層的に分類された場所のことである。
ディレクトリは、OS上でどのように永続的なデータを管理するかという方法を決定しているファイルシステムの要素の一部を成している。もともと、ハードディスクなどの生の装置のレベルでは、セクタという物理的な単位でデータが扱われている。しかし、アプリケーションから見た場合、これは低レベル過ぎて扱いづらい。そこで、OSはよりアプリケーションのロジックに近いデータの格納とアクセスの手段として、ファイルシステムを提供している。
どのような種類のデータをどこに置くべきかということは、OSごとに作法が決まっていることが多い。例えば、Linuxディストリビューションの一つであるCentOSなどでは、Web用の公開ファイルを置く場所は/var/www/htmlなどとなっている。この場所は、OSあるいはディストリビューションが違えば、変わることがある。またWindowsでは、インストーラからインストールされるアプリケーションの位置は、C:\Program Files以下となっている。
ディレクトリ階層の中で、ユーザーが現在参照しているディレクトリは、カレントディレクトリと呼ばれる。あるディレクトリの上のディレクトリは親ディレクトリなどと呼ばれ、下位のディレクトリが子ディレクトリあるいはサブディレクトリなどと呼ばれる。
ディレクトリの任意の場所を参照する機能として、Windowsではエクスプローラ、Mac OSではファインダーが用意されている。WindowsやMac OSはグラフィカルユーザーインターフェース(GUI)が採用されているため、アイコンをクリックする操作によって任意のディレクトリへアクセスすることができる。また、キャラクターユーザーインターフェース(CUI)のOSの場合は、コマンドライン入力で命令することによりディレクトリの移動が可能である。特に指定すれば階層を飛び越して直接アクセスすることもできる。
ディレクトリの考え方は、UNIX系OSにより普及したと言える。WindowsやMacintoshも、同様の思想で作られている。
ディレクトリと似た概念としてフォルダという概念がある。ディレクトリとフォルダの違いとしては下記の点が指摘できる。すなわち、ディレクトリがより物理的な構造に近い意味で使用されるのに対して、フォルダは、利用者に近いメタファーの一部として用いられることが多い。
ちなみに、ディレクトリサービスは、ネットワーク上の分散処理環境において、さまざまなサービスに関する情報を一元管理して提供するサービスや、あるいは、インターネット上でホームページ情報を紹介する電話帳のようなサービスを指す表現である。
ファイルシステム: | タイムスタンプ ダイナミックディスク ディスククオータ ディレクトリ トラックアットワンス ツリー構造 VFAT |
Directory クラス
アセンブリ: mscorlib (mscorlib.dll 内)


Directory クラスは、ディレクトリのコピー、移動、名前変更、作成、削除などの一般的な操作に使用します。Directory クラスは、ディレクトリに対する作成、アクセス、および書き込み操作についての DateTime 情報の取得および設定にも使用できます。
Directory のメソッドはすべて静的であるため、1 つの操作を実行するだけであれば、Directory のメソッドを使用する方が、対応する DirectoryInfo のインスタンス メソッドを使用するよりも効率的な場合があります。Directory のメソッドのほとんどは、操作対象のディレクトリのパスを必要とします。
Directory クラスの静的メソッドは、すべてのメソッドでセキュリティ チェックを実行します。オブジェクトを何回か再利用する場合は、このようなセキュリティ チェックが必ずしも必要ではなくなるため、これらの静的メソッドの代わりに DirectoryInfo の対応するインスタンス メソッドを使用することを検討してください。
![]() |
---|
入力文字列としてパスを受け入れるメンバでは、そのパスが正しい書式である必要があります。それ以外の場合は、例外が発生します。たとえば、パスが絶対パスであっても空白で始まっている場合、そのパスはクラスのメソッドではトリムされません。このため、パスが正しい書式にならず、例外が発生します。同様に、1 つのパスまたは複数のパスの組み合わせを絶対パスとして 2 度指定することはできません。たとえば、"c:\temp c:\windows" でも、ほとんどの場合において例外が発生します。パス文字列を受け入れるメソッドを使用するときは、パスが適切な書式であることを確認します。 |
パスを受け入れるメンバでは、ファイルまたはディレクトリを参照するパスを指定できます。指定するパスは、相対パス、またはサーバーおよび共有名を示す UNC (Universal Naming Convention) パスにすることができます。たとえば、次に示すパスはすべて有効なパスです。
-
C# では "c:\\MyDir"、Visual Basic では "c:\MyDir"。
-
C# では "MyDir\\MySubdir"、Visual Basic では "MyDir\MySubDir"。
-
C# では "\\\\MyServer\\MyShare"、Visual Basic では "\\MyServer\MyShare"。
既定では、すべてのユーザーに、新しいディレクトリに対する完全な読み書きアクセス権が与えられます。パス文字列がディレクトリの区切り記号で終わるディレクトリに対するアクセス許可を要求すると、結果として、そのディレクトリに含まれるすべてのサブディレクトリに対するアクセス許可を要求することになります ("C:\Temp\" など)。特定のディレクトリに対するアクセス許可のみが必要な場合は、文字列を "." 文字で終わらせる必要があります ("C:\Temp\." など)。
その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
Directory.Move DirectoryInfo.MoveTo | |
Directory.Delete DirectoryInfo.Delete | |
CreateDirectory Directory | |
CreateSubdirectory | |
GetDirectories GetDirectories | |
GetFileSystemInfos | |
Directory | |
GetFileSystemInfos | |

指定したディレクトリが存在するかどうかを判断して、存在する場合はそれを削除し、存在しない場合はそれを作成するコード例を次に示します。この例では、この後にディレクトリを移動し、ディレクトリ内にファイルを作成し、ディレクトリ内のファイルの数をカウントします。
Imports System Imports System.IO Public Class Test Public Shared Sub Main() 'Specify the directories you want to manipulate. Dim path As String = "c:\MyDir" Dim target As String = "c:\TestDir" Try ' Determine whethers the directory exists. If Directory.Exists(path) = False Then ' Create the directory. Directory.CreateDirectory(path) End If If Directory.Exists(target) Then ' Delete the target to ensure it is not there. Directory.Delete(target, True) End If ' Move the directory. Directory.Move(path, target) 'Create a file in the directory. File.CreateText(target + "\myfile.txt") 'Count the files in the target. Console.WriteLine("The number of files in {0} is {1}", _ target, Directory.GetFiles(target).Length) Catch e As Exception Console.WriteLine("The process failed: {0}", e.ToString()) End Try End Sub End Class
using System; using System.IO; class Test { public static void Main() { // Specify the directories you want to manipulate. string path = @"c:\MyDir"; string target = @"c:\TestDir"; try { // Determine whether the directory exists. if (!Directory.Exists(path)) { // Create the directory it does not exist. Directory.CreateDirectory(path); } if (Directory.Exists(target)) { // Delete the target to ensure it is not there. Directory.Delete(target, true); } // Move the directory. Directory.Move(path, target); // Create a file in the directory. File.CreateText(target + @"\myfile.txt"); // Count the files in the target directory. Console.WriteLine("The number of files in {0} is {1}", target, Directory.GetFiles(target).Length); } catch (Exception e) { Console.WriteLine("The process failed: {0}", e.ToString()); } finally {} } }
using namespace System; using namespace System::IO; int main() { // Specify the directories you want to manipulate. String^ path = "c:\\MyDir"; String^ target = "c:\\TestDir"; try { // Determine whether the directory exists. if ( !Directory::Exists( path ) ) { // Create the directory it does not exist. Directory::CreateDirectory( path ); } if ( Directory::Exists( target ) ) { // Delete the target to ensure it is not there. Directory::Delete( target, true ); } // Move the directory. Directory::Move( path, target ); // Create a file in the directory. File::CreateText( String::Concat( target, "\\myfile.txt" ) ); // Count the files in the target directory. Console::WriteLine( "The number of files in {0} is {1}", target, Directory::GetFiles( target )->Length ); } catch ( Exception^ e ) { Console::WriteLine( "The process failed: {0}", e ); } }
import System.*; import System.IO.*; class Test { public static void main(String[] args) { // Specify the directories you want to manipulate. String path = "c:\\MyDir"; String target = "c:\\TestDir"; try { // Determine whether the directory exists. if (!(Directory.Exists(path))) { // Create the directory it does not exist. Directory.CreateDirectory(path); } if (Directory.Exists(target)) { // Delete the target to ensure it is not there. Directory.Delete(target, true); } // Move the directory. Directory.Move(path, target); // Create a file in the directory. File.CreateText(target + "\\myfile.txt"); // Count the files in the target directory. Console.WriteLine("The number of files in {0} is {1}", target, (Int32)Directory.GetFiles(target).length); } catch (System.Exception e) { Console.WriteLine("The process failed: {0}", e.ToString()); } finally { } } //main } //Test
ディレクトリのサイズを計算する方法のコード例を次に示します。
' The following example calculates the size of a directory ' and its subdirectories, if any, and displays the total size ' in bytes. Imports System Imports System.IO Imports Microsoft.VisualBasic Public Class ShowDirSize Public Shared Function DirSize(ByVal d As DirectoryInfo) As Long Dim Size As Long = 0 ' Add file sizes. Dim fis As FileInfo() = d.GetFiles() Dim fi As FileInfo For Each fi In fis Size += fi.Length Next fi ' Add subdirectory sizes. Dim dis As DirectoryInfo() = d.GetDirectories() Dim di As DirectoryInfo For Each di In dis Size += DirSize(di) Next di Return Size End Function 'DirSize Public Overloads Shared Sub Main(ByVal args() As String) If args.Length <> 1 Then Console.WriteLine("You must provide a directory argument at the command line.") Else Dim d As New DirectoryInfo(args(0)) Console.WriteLine("The size of {0} and its subdirectories is {1} bytes.", d, DirSize(d)) End If End Sub 'Main End Class 'ShowDirSize
// The following example calculates the size of a directory // and its subdirectories, if any, and displays the total size // in bytes. using System; using System.IO; public class ShowDirSize { public static long DirSize(DirectoryInfo d) { long Size = 0; // Add file sizes. FileInfo[] fis = d.GetFiles(); foreach (FileInfo fi in fis) { Size += fi.Length; } // Add subdirectory sizes. DirectoryInfo[] dis = d.GetDirectories(); foreach (DirectoryInfo di in dis) { Size += DirSize(di); } return(Size); } public static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("You must provide a directory argument at the command line."); } else { DirectoryInfo d = new DirectoryInfo(args[0]); Console.WriteLine("The size of {0} and its subdirectories is {1} bytes.", d, DirSize(d)); } } }
// The following example calculates the size of a directory // and its subdirectories, if any, and displays the total size // in bytes. using namespace System; using namespace System::IO; long DirSize( DirectoryInfo^ d ) { long Size = 0; // Add file sizes. array<FileInfo^>^fis = d->GetFiles(); System::Collections::IEnumerator^ myEnum = fis->GetEnumerator(); while ( myEnum->MoveNext() ) { FileInfo^ fi = safe_cast<FileInfo^>(myEnum->Current); Size += (long)fi->Length; } array<DirectoryInfo^>^dis = d->GetDirectories(); while ( myEnum->MoveNext() ) { DirectoryInfo^ di = safe_cast<DirectoryInfo^>(myEnum->Current); Size += DirSize( di ); } return Size; } int main() { array<String^>^args = Environment::GetCommandLineArgs(); if ( args->Length != 2 ) { Console::WriteLine( "You must provide a directory argument at the command line." ); } else { DirectoryInfo^ d = gcnew DirectoryInfo( args[ 1 ] ); Console::WriteLine( "The size of {0} and its subdirectories is {1} bytes.", d, DirSize( d ) ); } }

System.IO.Directory


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Directory メソッド


Directory メンバ
ディレクトリやサブディレクトリを通じて、作成、移動、および列挙するための静的メソッドを公開します。このクラスは継承できません。
Directory データ型で公開されるメンバを以下の表に示します。


ディレクトリ (曖昧さ回避)
- DIRECTORYのページへのリンク