Dir
FilenameArray = Dir ( Directory AS String [ , Pattern AS String , Filter AS Integer ] ) AS String[]
返回位于
Directory 目录中与
Pattern 和
Filter 条件匹配的文件名,并存储于一个字符串数组中。
Pattern可以包含与
LIKE 操作一样的通配符。如果没有指定Pattern,会返回任何文件名。
过滤器指定将返回的文件类型。
过滤器可以是以下值之一:
If
Options is not specified, all files and directories are returned.
The file names returned are relative to the directory searched. They do not contain the path to the searched directory.
Since 3.20
If you add the
gb.FullPath
constant to the
Options argument, the
Directory path is added to each returned file.
Note that the pattern does not apply to the directory part in that case.
示例
' 以字母顺序打印directory目录中的png图像文件文件名
SUB PrintDirectory(Directory AS String)
DIM File AS String
FOR EACH File IN Dir(Directory, "*.png").Sort()
PRINT File
NEXT
END
' 打印用户主目录中所有非隐藏文件
DIM fileName AS String
FOR EACH fileName IN Dir(User.Home, "[^.]*")
PRINT fileName
NEXT
' 打印用户主目录中的png和jpeg图像文件名
DIM Directory AS String
DIM Files AS String[]
DIM FileName AS String
Directory = System.User.Home
Files = Dir(Directory, "*.png")
Files.Insert(Dir(Directory, "*.jpg"))
Files.Insert(Dir(Directory, "*.jpeg"))
FOR EACH FileName IN Files
PRINT FileName
NEXT
'仅仅打印用户主目录中的文件名
DIM fileName AS String
FOR EACH fileName IN Dir(User.Home, "*", gb.File)
PRINT fileName
NEXT
' 仅仅打印用户主目录中的子目录名
DIM directoryName AS String
FOR EACH directoryName IN Dir(User.Home, "*", gb.Directory)
PRINT directoryName
NEXT
'打印用户主目录中的非隐藏目录名
DIM directoryName AS String
FOR EACH directoryName IN Dir(User.Home, "[^.]*", gb.Directory)
PRINT directoryName
NEXT
' 列出系统设备清单
DIM deviceName AS String
FOR EACH deviceName IN Dir("/dev", "*", gb.Device)
PRINT deviceName
NEXT
参见