Dir Function

νŠΉμ • 파일 λ˜λŠ” λ””λ ‰ν† λ¦¬μ˜ μ΄λ¦„μ΄λ‚˜ μ§€μ •ν•œ 검색 κ²½λ‘œμ™€ μΌμΉ˜ν•˜λŠ” λ“œλΌμ΄λΈŒ λ˜λŠ” 디렉토리에 μžˆλŠ” λͺ¨λ“  파일과 λ””λ ‰ν† λ¦¬μ˜ 이름을 κ΅¬ν•©λ‹ˆλ‹€.

ꡬ문:

Dir [(Text As String) [, Attrib As Integer]]

λ°˜ν™˜ κ°’:

String

맀개 λ³€μˆ˜:

Text: 검색 경둜, 디렉토리 λ˜λŠ” νŒŒμΌμ„ μ§€μ •ν•˜λŠ” μž„μ˜μ˜ λ¬Έμžμ—΄ μ‹μž…λ‹ˆλ‹€. 이 μΈμˆ˜λŠ” Dir ν•¨μˆ˜λ₯Ό 처음 ν˜ΈμΆœν•  λ•Œλ§Œ 지정할 수 μžˆμŠ΅λ‹ˆλ‹€. ν•„μš”ν•˜λ©΄ 경둜λ₯Ό URL ν‘œκΈ°λ²•μœΌλ‘œ μž…λ ₯ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

Attrib: λΉ„νŠΈ λ‹¨μœ„μ˜ 파일 속성을 μ§€μ •ν•˜λŠ” μž„μ˜μ˜ μ •μˆ˜ μ‹μž…λ‹ˆλ‹€. Dir ν•¨μˆ˜λŠ” μ§€μ •ν•œ 속성과 μΌμΉ˜ν•˜λŠ” 파일 λ˜λŠ” λ””λ ‰ν† λ¦¬λ§Œ ν‘œμ‹œν•©λ‹ˆλ‹€. 속성 값을 μΆ”κ°€ν•˜μ—¬ μ—¬λŸ¬ 속성을 κ²°ν•©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

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 잘λͺ»λœ ν”„λ‘œμ‹œμ € ν˜ΈμΆœμž…λ‹ˆλ‹€.

53 νŒŒμΌμ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.

예:

Sub ExampleDir

REM Displays all files and directories

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