FileSystem.GetAttr(String) Methode

Definitie

Retourneert een FileAttribute waarde die de kenmerken van een bestand, map of map vertegenwoordigt. De My functie biedt u betere productiviteit en prestaties in bestands-I/O-bewerkingen dan FileAttribute. Zie FileSystem voor meer informatie.

public:
 static Microsoft::VisualBasic::FileAttribute GetAttr(System::String ^ PathName);
public static Microsoft.VisualBasic.FileAttribute GetAttr(string PathName);
static member GetAttr : string -> Microsoft.VisualBasic.FileAttribute
Public Function GetAttr (PathName As String) As FileAttribute

Parameters

PathName
String

Required. Een tekenreeksexpressie waarmee een bestand, map of mapnaam wordt opgegeven. PathName kan de map of map en het station bevatten.

Retouren

Een bitsgewijze combinatie van de opsommingswaarden.

Uitzonderingen

Pathname is ongeldig of bevat jokertekens.

Het doelbestand bestaat niet.

Voorbeelden

In dit voorbeeld wordt de GetAttr functie gebruikt om de kenmerken van een bestand en map te bepalen.

Dim MyAttr As FileAttribute
' Assume file TESTFILE is normal and readonly.
MyAttr = GetAttr("C:\TESTFILE.txt")   ' Returns vbNormal.

' Test for normal.
If (MyAttr And FileAttribute.Normal) = FileAttribute.Normal Then
    MsgBox("This file is normal.")
End If

' Test for normal and readonly.
Dim normalReadonly As FileAttribute
normalReadonly = FileAttribute.Normal Or FileAttribute.ReadOnly
If (MyAttr And normalReadonly) = normalReadonly Then
    MsgBox("This file is normal and readonly.")
End If

' Assume MYDIR is a directory or folder.
MyAttr = GetAttr("C:\MYDIR")
If (MyAttr And FileAttribute.Directory) = FileAttribute.Directory Then
    MsgBox("MYDIR is a directory")
End If

Opmerkingen

Als u wilt bepalen welke kenmerken zijn ingesteld, gebruikt u de And operator om een bitsgewijze vergelijking uit te voeren van de waarde die wordt geretourneerd door de GetAttr functie en de waarde van het gewenste afzonderlijke bestandskenmerk. Als het resultaat niet nul is, wordt dat kenmerk is ingesteld voor het benoemde bestand. De retourwaarde van de volgende And expressie is bijvoorbeeld nul als het Archive kenmerk niet is ingesteld:

Result = GetAttr(FName) And vbArchive

Er wordt een niet-nulwaarde geretourneerd als het Archive kenmerk is ingesteld.

Van toepassing op

Zie ook