Dir Function

āĻĄā§āĻ°āĻžāĻ‡āĻ­ āĻ…āĻĨāĻŦāĻž āĻĄāĻŋāĻ°ā§‡āĻ•ā§āĻŸāĻ°āĻŋāĻ° āĻ‰āĻ˛ā§āĻ˛ā§‡āĻ–āĻŋāĻ¤ āĻ…āĻ¨ā§āĻ¸āĻ¨ā§āĻ§āĻžāĻ¨ āĻĒāĻžāĻĨā§‡āĻ° āĻ¸āĻžāĻĨā§‡ āĻŽāĻŋāĻ˛ā§‡ āĻ¯āĻžā§Ÿ āĻāĻŽāĻ¨ āĻāĻ•āĻŸāĻŋ āĻĢāĻžāĻ‡āĻ˛, āĻĄāĻŋāĻ°ā§‡āĻ•ā§āĻŸāĻ°āĻŋ āĻ…āĻĨāĻŦāĻž āĻ¸āĻ•āĻ˛ āĻĢāĻžāĻ‡āĻ˛ āĻāĻŦāĻ‚ āĻĄāĻŋāĻ°ā§‡āĻ•ā§āĻŸāĻ°āĻŋ āĻĒā§āĻ°āĻĻāĻžāĻ¨ āĻ•āĻ°ā§‡ āĻĨāĻžāĻ•ā§‡āĨ¤

Syntax:


Dir [(PathName As String [, Attributes As Integer])]

Return value:

āĻ¸ā§āĻŸā§āĻ°āĻŋāĻ‚

Parameters:

PathName: Any string expression that specifies the search path, directory or file. This argument can only be specified the first time that you call the Dir function. If you want, you can enter the path in URL notation.

Attributes:Any integer expression that specifies bitwise file attributes. The Dir function only returns files or directories that match the specified attributes. You can combine several attributes by adding the attribute values:

0 : āĻ¸ā§āĻŦāĻžāĻ­āĻžāĻŦāĻŋāĻ• āĻĢāĻžāĻ‡āĻ˛āĨ¤

16 : āĻļā§āĻ§ā§āĻŽāĻžāĻ¤ā§āĻ° āĻĄāĻŋāĻ°ā§‡āĻ•ā§āĻŸāĻ°ā§€āĻ° āĻ¨āĻžāĻŽ āĻĢā§‡āĻ°āĻ¤ āĻĒāĻžāĻ āĻžā§ŸāĨ¤

āĻĢāĻžāĻ‡āĻ˛ āĻ…āĻĨāĻŦāĻž āĻĄāĻŋāĻ°ā§‡āĻ•ā§āĻŸāĻ°āĻŋ āĻ‰āĻĒāĻ¸ā§āĻĨāĻŋāĻ¤ āĻ†āĻ›ā§‡ āĻ•āĻŋāĻ¨āĻž āĻ¤āĻž āĻĒāĻ°ā§€āĻ•ā§āĻˇāĻž āĻ•āĻ°āĻžāĻ° āĻœāĻ¨ā§āĻ¯ āĻ…āĻĨāĻŦāĻž āĻāĻ•āĻŸāĻŋ āĻ‰āĻ˛ā§āĻ˛ā§‡āĻ–āĻŋāĻ¤ āĻĄāĻŋāĻ°ā§‡āĻ•ā§āĻŸāĻ°āĻŋāĻ¤ā§‡ āĻ¸āĻ•āĻ˛ āĻĢāĻžāĻ‡āĻ˛ āĻāĻŦāĻ‚ āĻĢā§‹āĻ˛ā§āĻĄāĻžāĻ° āĻ¨āĻŋāĻ°ā§āĻ§āĻžāĻ°āĻŖ āĻ•āĻ°āĻžāĻ° āĻœāĻ¨ā§āĻ¯ āĻāĻ‡ āĻŦā§ˆāĻļāĻŋāĻˇā§āĻŸā§āĻ¯āĻžāĻŦāĻ˛ā§€ āĻŦā§āĻ¯āĻŦāĻšāĻžāĻ° āĻ•āĻ°ā§āĻ¨āĨ¤

āĻĢāĻžāĻ‡āĻ˛ āĻ‰āĻĒāĻ¸ā§āĻĨāĻŋāĻ¤ āĻ†āĻ›āĻŋ āĻ•āĻŋāĻ¨āĻž āĻ¤āĻž āĻĒāĻ°ā§€āĻ•ā§āĻˇāĻž āĻ•āĻ°āĻžāĻ° āĻœāĻ¨ā§āĻ¯ āĻĢāĻžāĻ‡āĻ˛ā§‡āĻ° āĻ¸āĻŽā§āĻĒā§‚āĻ°ā§āĻŖ āĻĒāĻžāĻĨ āĻāĻŦāĻ‚ āĻ¨āĻžāĻŽ āĻ¸āĻ¨ā§āĻ¨āĻŋāĻŦā§‡āĻļ āĻ•āĻ°āĻžāĻ¨āĨ¤ āĻ¯āĻĻāĻŋ āĻĢāĻžāĻ‡āĻ˛ āĻ…āĻĨāĻŦāĻž āĻĄāĻŋāĻ°ā§‡āĻ•ā§āĻŸāĻ°āĻŋāĻ° āĻ¨āĻžāĻŽ āĻŦāĻŋāĻĻā§āĻ¯āĻŽāĻžāĻ¨ āĻ¨āĻž āĻĨāĻžāĻ•ā§‡ āĻ¤āĻžāĻšāĻ˛ā§‡ Dir āĻĢāĻžāĻ‚āĻļāĻ¨āĻŸāĻŋ āĻāĻ•āĻŸāĻŋ āĻļā§‚āĻ¨ā§āĻ¯ āĻĻā§ˆāĻ°ā§āĻ˜ā§āĻ¯ā§‡āĻ° āĻ¸ā§āĻŸā§āĻ°āĻŋāĻ‚("") āĻĒā§āĻ°āĻĻāĻžāĻ¨ āĻ•āĻ°ā§‡ āĻĨāĻžāĻ•ā§‡āĨ¤

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 Invalid procedure call

53 File not found 53 File not found

Example:


Sub ExampleDir
REM āĻ āĻ¸āĻ•āĻ˛ āĻĢāĻžāĻ‡āĻ˛ āĻāĻŦāĻ‚ āĻĄāĻŋāĻ°ā§‡āĻ•ā§āĻŸāĻ°ā§€ āĻĒā§āĻ°āĻĻāĻ°ā§āĻļāĻŋāĻ¤ āĻšā§Ÿ
Dim sPath As String
Dim sDir As String, sValue As String
    sDir="Directories:"
    sPath = CurDir
    sValue = Dir$(sPath + getPathSeparator + "*",16)
    Do
        If sValue <> "." And sValue <> ".." Then
            If (GetAttr( sPath + getPathSeparator + sValue) And 16) >0 Then
                REM get the directories
                sDir = sDir & chr(13) & sValue
            End If
        End If
        sValue = Dir$
    Loop Until sValue = ""
    MsgBox sDir,0,sPath
End Sub

Please support us!