FileSystem.Dir メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定したパターンまたはファイル属性に一致するファイル、ディレクトリ、またはフォルダーの名前、またはドライブのボリューム ラベルを表す文字列を返します。
FileSystemを使用すると、Dir関数よりもファイル I/O 操作の生産性とパフォーマンスが向上します。 詳細については、GetDirectoryInfo(String) を参照してください。
オーバーロード
| 名前 | 説明 |
|---|---|
| Dir() |
指定したパターンまたはファイル属性に一致するファイル、ディレクトリ、またはフォルダーの名前、またはドライブのボリューム ラベルを表す文字列を返します。
FileSystemを使用すると、 |
| Dir(String, FileAttribute) |
指定したパターンまたはファイル属性に一致するファイル、ディレクトリ、またはフォルダーの名前、またはドライブのボリューム ラベルを表す文字列を返します。
FileSystemを使用すると、 |
Dir()
- ソース:
- FileSystem.vb
- ソース:
- FileSystem.vb
- ソース:
- FileSystem.vb
- ソース:
- FileSystem.vb
- ソース:
- FileSystem.vb
指定したパターンまたはファイル属性に一致するファイル、ディレクトリ、またはフォルダーの名前、またはドライブのボリューム ラベルを表す文字列を返します。
FileSystemを使用すると、Dir関数よりもファイル I/O 操作の生産性とパフォーマンスが向上します。 詳細については、GetDirectoryInfo(String) を参照してください。
public:
static System::String ^ Dir();
public static string Dir();
static member Dir : unit -> string
Public Function Dir () As String
返品
指定したパターンまたはファイル属性に一致するファイル、ディレクトリ、またはフォルダーの名前、またはドライブのボリューム ラベルを表す文字列。
例
この例では、 Dir 関数を使用して、特定のファイルとディレクトリが存在するかどうかを確認します。
Dim MyFile, MyPath, MyName As String
' Returns "WIN.INI" if it exists.
MyFile = Dir("C:\WINDOWS\WIN.INI")
' Returns filename with specified extension. If more than one *.INI
' file exists, the first file found is returned.
MyFile = Dir("C:\WINDOWS\*.INI")
' Call Dir again without arguments to return the next *.INI file in the
' same directory.
MyFile = Dir()
' Return first *.TXT file, including files with a set hidden attribute.
MyFile = Dir("*.TXT", vbHidden)
' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
' Display entry only if it's a directory.
MsgBox(MyName)
End If
MyName = Dir() ' Get next entry.
Loop
注釈
Dir関数では、複数のファイルを指定するための複数文字 (*) ワイルドカードと単一文字 (?) ワイルドカードの使用がサポートされています。
VbVolume は、特定のファイル名ではなく、ドライブのボリューム ラベルを返します。
PathName関数を初めて呼び出す場合は、Dirを指定する必要があります。 次の項目を取得するには、パラメーターを指定せずに Dir 関数を後続で呼び出します。
Important
Dir関数を正しく実行するには、実行中のコードにReadのPathDiscoveryフラグとFileIOPermissionフラグを付与する必要があります。 詳細については、「 FileIOPermission、 SecurityException、 およびコード アクセス許可」を参照してください。
Attributes引数の列挙値は次のとおりです。
| 価値 | 定数 | Description |
|---|---|---|
Normal |
vbnormal |
Default. 属性のないファイルを指定します。 |
ReadOnly |
vbReadOnly |
読み取り専用ファイルと、属性のないファイルも指定します。 |
Hidden |
vbHidden |
非表示のファイルと、属性のないファイルも指定します。 |
System |
vbSystem |
システム ファイルと、属性のないファイルも指定します。 |
Volume |
vbVolume |
ボリューム ラベルを指定します。その他の属性が指定されている場合、 vbVolume は無視されます。 |
Directory |
vbDirectory |
ディレクトリまたはフォルダー、および属性のないファイルも指定します。 |
Archive |
vbArchive |
最後のバックアップ以降、ファイルが変更されています。 |
Alias |
vbAlias |
ファイルの名前が異なります。 |
Note
これらの列挙型はVisual Basic言語で指定され、実際の値ではなくコード内の任意の場所で使用できます。
こちらもご覧ください
適用対象
Dir(String, FileAttribute)
- ソース:
- FileSystem.vb
- ソース:
- FileSystem.vb
- ソース:
- FileSystem.vb
- ソース:
- FileSystem.vb
- ソース:
- FileSystem.vb
指定したパターンまたはファイル属性に一致するファイル、ディレクトリ、またはフォルダーの名前、またはドライブのボリューム ラベルを表す文字列を返します。
FileSystemを使用すると、Dir関数よりもファイル I/O 操作の生産性とパフォーマンスが向上します。 詳細については、GetDirectoryInfo(String) を参照してください。
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static string Dir(string PathName, Microsoft.VisualBasic.FileAttribute Attributes = Microsoft.VisualBasic.FileAttribute.Normal);
public static string Dir(string PathName, Microsoft.VisualBasic.FileAttribute Attributes = Microsoft.VisualBasic.FileAttribute.Normal);
public static string Dir(string Pathname, Microsoft.VisualBasic.FileAttribute Attributes = Microsoft.VisualBasic.FileAttribute.Normal);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member Dir : string * Microsoft.VisualBasic.FileAttribute -> string
static member Dir : string * Microsoft.VisualBasic.FileAttribute -> string
Public Function Dir (PathName As String, Optional Attributes As FileAttribute = Microsoft.VisualBasic.FileAttribute.Normal) As String
Public Function Dir (Pathname As String, Optional Attributes As FileAttribute = Microsoft.VisualBasic.FileAttribute.Normal) As String
パラメーター
- PathNamePathname
- String
このフィールドは省略可能です。 ファイル名、ディレクトリまたはフォルダー名、またはドライブ ボリューム ラベルを指定する文字列式。
""が見つからない場合は、長さ 0 の文字列 (PathName) が返されます。
- Attributes
- FileAttribute
このフィールドは省略可能です。 ファイル属性を指定する値を持つ列挙または数値式。 省略すると、 Dir は Pathname に一致するが属性がないファイルを返します。
返品
指定したパターンまたはファイル属性に一致するファイル、ディレクトリ、またはフォルダーの名前、またはドライブのボリューム ラベルを表す文字列。
- 属性
例
この例では、 Dir 関数を使用して、特定のファイルとディレクトリが存在するかどうかを確認します。
Dim MyFile, MyPath, MyName As String
' Returns "WIN.INI" if it exists.
MyFile = Dir("C:\WINDOWS\WIN.INI")
' Returns filename with specified extension. If more than one *.INI
' file exists, the first file found is returned.
MyFile = Dir("C:\WINDOWS\*.INI")
' Call Dir again without arguments to return the next *.INI file in the
' same directory.
MyFile = Dir()
' Return first *.TXT file, including files with a set hidden attribute.
MyFile = Dir("*.TXT", vbHidden)
' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
' Display entry only if it's a directory.
MsgBox(MyName)
End If
MyName = Dir() ' Get next entry.
Loop
注釈
Dir関数では、複数のファイルを指定するための複数文字 (*) ワイルドカードと単一文字 (?) ワイルドカードの使用がサポートされています。
VbVolume は、特定のファイル名ではなく、ドライブのボリューム ラベルを返します。
PathName関数を初めて呼び出す場合は、Dirを指定する必要があります。 次の項目を取得するには、パラメーターを指定しない Dir 関数に対して後続の呼び出しを行います。
Important
Dir関数を正しく実行するには、実行中のコードにReadのPathDiscoveryフラグとFileIOPermissionフラグを付与する必要があります。 詳細については、「 FileIOPermission、 SecurityException、 およびコード アクセス許可」を参照してください。
Attributes引数の列挙値は次のとおりです。値|定数|説明| |-|-|--| |Normal|vbnormal|既定。 属性のないファイルを指定します。||ReadOnly|vbReadOnly|属性のないファイルに加えて、読み取り専用ファイルを指定します。||Hidden|vbHidden|属性のないファイルに加えて、非表示のファイルを指定します。||System|vbSystem|属性のないファイルに加えて、システム ファイルを指定します。||Volume|vbVolume|ボリューム ラベルを指定します。その他の属性が指定されている場合、 vbVolume は無視されます。| |Directory|vbDirectory|属性のないファイルに加えて、ディレクトリまたはフォルダーを指定します。||Archive|vbArchive|前回のバックアップ以降にファイルが変更されました。||Alias|vbAlias|ファイル名が異なります。|
Note
これらの列挙型はVisual Basic言語で指定され、実際の値の代わりにコード内の任意の場所で使用できます。