Dir () function

' 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 a directory.
         MsgBox(MyName)
      End If   
   MyName = Dir()   ' Get next entry.
Loop

I am looking at the code above. I specifically don’t understand what "MyName = Dir ()" does. It is commented that he gets the next record, but I don’t understand how she gets the next record - in particular, what does Dir () do?

+4
source share
2 answers

Dir - a function that has a boundary effect.

first call Dir: MyName = Dir(MyPath, vbDirectory)initializes the internal elements Dirand returns the first entry in the directory.

Subsequent calls Diruse the same context, each time leading to the contents of the directory MyPath.

( / Dir), , .

+10

Dir() MSDN,

, , , , .

+2

Source: https://habr.com/ru/post/1653319/


All Articles