Dir Function

Devuelve'l nome d'un ficheru, directoriu o tolos ficheros y directorios d'una unidá o directoriu que coincidan cola ruta d'accesu de busca especificada.

Sintaxis:

Dir [(Testu As String) [, Atrib As Integer]]

Valor de torna:

Cadena

Parámetros:

Testu: Cualquier espresión de cadena qu'especifique la ruta d'accesu de busca, el directoriu o el ficheru. Esti argumentu namái pue especificase la primer vegada que se llame a la función Dir. Si deseyar, la ruta d'accesu pue escribise na notación URL.

Atrib: Cualquier espresión entera qu'especifique atributos de ficheru bit a bit. La función Dir namái devuelve ficheros o directorios que coincidan colos atributos especificaos. Puen combinase dellos atributos añediendo los valores siguientes:

0 : Ficheros normales.

16 : Namái devuelve'l nome del directoriu.

Esti atributu usar pa comprobar si un ficheru o directoriu esisten o pa determinar tolos ficheros y carpetes d'un directoriu específicu.

Pa comprobar si un ficheru esiste, escriba la ruta d'accesu completa y el nome del ficheru. Si'l nome de ficheru o de directoriu nun esisten, la función Dir devuelve una cadena de longitud cero ("").

To generate a list of all existing files in a specific directory, proceed as follows: The first time you call the Dir function, specify the complete search path for the files, for example, "D:\Files\*.ods". If the path is correct and the search finds at least one file, the Dir function returns the name of the first file that matches the search path. To return additional file names that match the path, call Dir again, but with no arguments.

To return directories only, use the attribute parameter. The same applies if you want to determine the name of a volume (for example, a hard drive partition).

Error codes:

5 Llamada a procedimientu non válida

53 Ficheru non atopáu

Exemplu:

Sub ExampleDir

' Amuesa tolos ficheros y direutorios

Dim sPath As String

Dim sDir As String, sValue As String

    sDir="Directorios:"

    sPath = CurDir

    sValue = Dir$(sPath + getPathSeparator + "*",16)

    Do

        If sValue <> "." And sValue <> ".." Then

            If (GetAttr( sPath + getPathSeparator + sValue) And 16) >0 Then

                ' Algamar los direutorios

                sDir = sDir & chr(13) & sValue

            End If

        End If

        sValue = Dir$

    Loop Until sValue = ""

    MsgBox sDir,0,sPath

End Sub