# Array.&ltstring&gt FileSystemManager.readdirSync(string dirPath)

with Promise style call: Not supported

Mini Program plugin: Support, need to Mini Program base library version no less than 2.19.2

FileSystemManager.readdir The synchronous version of

# parameter

# string dirPath

Directory path to read (Local path)

# Note

  • The readdir interface cannot access the file system root path(wxfile://)。

# Return value

# Array.&ltstring&gt files

Specifies an array of file names in a directory.

# error

Error code Error message Introductions
fail No such file or directory ${dirPath} Directory does not exist
fail not a directory ${dirPath} dirPath Not a directory.
fail permission denied, open ${dirPath} Specified filePath Path not read
fail sdcard not mounted Android sdcard Mount failure

# sample code

const fs = wx.getFileSystemManager()
fs.readdir({
  dirPath: `${wx.env.USER_DATA_PATH}/example`,
  success(res) {
    console.log(res.files)
  },
  fail(res) {
    console.error(res)
  }
})

// Synchronous interface
try {
  const res = fs.readdirSync(`${wx.env.USER_DATA_PATH}/example`)
  console.log(res)
} catch(e) {
  console.error(e)
}