首页 > lang > dir 
 en fr de es it nl pl pt pt_BR mk sq ca hu cs tr ar fa id vi ko ja ru zh eo
前一个  下一个  编辑  重命名  撤销  搜索  管理  
文档  
警告! 该页面未翻译。  参见英文版 
Dir
FilenameArray = Dir ( Directory AS String [ , Pattern AS String , Filter AS Integer ] ) AS String[]

Returns a string array that contains the names of files located in Directory that matches the Pattern and the Filter.

The file names returned are relative, they do not contain the searched directory.

Example

' Print the png image files in a directory, in alphabetical order.

SUB PrintDirectory(Directory AS String)

  DIM File AS String

  FOR EACH File IN Dir(Directory, "*.png").Sort()
    PRINT File
  NEXT

END

' Print all non hidden files in the user home directory.

DIM fileName AS String

FOR EACH fileName IN Dir(User.Home, "[^.]*")
  PRINT fileName
NEXT

' Print png and jpeg images in the user home directory.

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

' Prints files only in the user home directory.

DIM fileName AS String

FOR EACH fileName IN Dir(User.Home, "*", gb.File)
  PRINT fileName
NEXT

' Prints sub directories only in the user home directory.

DIM directoryName AS String

FOR EACH directoryName IN Dir(User.Home, "*", gb.Directory)
  PRINT directoryName
NEXT

' Prints non hidden sub directories in the user home directory.

DIM directoryName AS String

FOR EACH directoryName IN Dir(User.Home, "[^.]*", gb.Directory)
  PRINT directoryName
NEXT

' List system devices.

DIM deviceName AS String

FOR EACH deviceName IN Dir("/dev", "*", gb.Device)
  PRINT deviceName
NEXT

参见

File & Directory Functions, File & Directory Paths