File system utilities for lua.
Clone or download
Latest commit 3276321 Dec 23, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib chore: bump version to 0.1 Dec 22, 2018
.gitignore init Sep 9, 2018
LICENSE chore: add license Sep 22, 2018
README.md doc: update readme Dec 23, 2018
dist.ini chore: append opm and luarocks file Dec 22, 2018
lua-fs-module-0.1-1.rockspec chore: append opm and luarocks file Dec 22, 2018

README.md

lua-fs-module

MIT

API

  • fs.read
  • fs.readFile
  • fs.readdir
  • fs.write
  • fs.writeFile
  • fs.appendToFile
  • fs.exists
  • fs.copy
  • fs.move
  • fs.mkdir
  • fs.rmdir
  • fs.unlink
  • fs.rm
  • fs.remove
  • fs.rmAll
  • fs.removeAll
  • fs.chown
  • fs.chmod
  • fs.isDir
  • fs.isFile

Usage

local fs = require "fs"

local content, err = fs.read(fileOrDir)
-- 读取目标为文件时,content 为文件内容
-- 读取目标为目录时,content 为 { "a.txt", "b.txt" }

local content, err = fs.readFile(file)
local files, err = fs.readdir(dir, n)
-- files: ``{ "a.txt", "b.txt" }``
-- n: 重试次数,默认 3 次

local ok, err = fs.write(file, content)
local ok, err = fs.writeFile(file, content)
local ok, err = fs.appendToFile(file, content)
local exists = fs.exists(file)
local ok, err = fs.copy(file1, file2)
local ok, err = fs.move(fileOrDir1, fileOrDir2)
local ok, err = fs.mkdir(dir)
local ok, err = fs.rmdir(dir)
local ok, err = fs.unlink(file)
local ok, err = fs.rm(file)
local ok, err = fs.remove(file)
local ok, err = fs.rmAll(fileOrDir)
local ok, err = fs.removeAll(fileOrDir)
local ok, err = fs.chown(fileOrDir, user)
local ok, err = fs.chmod(fileOrDir, 777)
local yes = fs.isDir(dir)
local yes = fs.isFile(file)

License

MIT License

Copyright (c) 2018 xiedacon