Dir() function understanding

后端 未结 2 929
庸人自扰
庸人自扰 2021-01-18 08:34
\' Display the names in C:\\ that represent directories.
MyPath = \"c:\\\"   \' Set the path.
MyName = Dir(MyPath, vbDirectory)   \' Retrieve the first entry.
Do Whi         


        
2条回答
  •  -上瘾入骨i
    2021-01-18 08:41

    Dir is function which has a edge effect.

    the first call to Dir: MyName = Dir(MyPath, vbDirectory) initializes the Dir internals and returns the first directory entry.

    Subsequent calls to Dir use the same context, yielding MyPath directory contents one by one.

    It's not reentrant (which is also why you can't nest/recurse multiple loops using Dir), not very elegant, but that's how it works.

提交回复
热议问题