3 Star 1 Fork 0

黑小马 / hsp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
file.md 2.36 KB
一键复制 编辑 原始数据 按行查看 历史
黑小马 提交于 2022-02-26 11:10 . file 读写增加

File 模块

导入模块


var file = require("file")

判断所给路径是否为文件夹

  • 参数描述 path
  • bool
console.log(file.IsDir("D:\\Go"))

判断所给路径是否为文件

  • 参数描述 path
  • bool
console.log(file.IsFile("D:\\Go"))

判断所给路径文件/文件夹是否存在

  • 参数描述 path
  • bool
console.log(file.Exists("D:\\Go"))

创建文件

  • 参数描述 path
  • bool
console.log(file.CreateFile("D:\\Go\\a.txt"))

创建未定义路径的文件(自动创建)

  • 参数描述 path
  • bool
console.log(file.CreateFileWithDirs("D:\\Go\\xxx\\a.txt"))

创建路径

  • 参数描述 path
  • bool
console.log(file.CreateDir("D:\\Go\\xxx\\xx\\"))

创建多层路径

  • 参数描述 path
  • bool
console.log(file.CreateDirAll("D:\\Go\\xxx\\xx\\xx\\xx\\"))

删除文件夹或者文件,哪怕不存在,文件夹不为空,都可以删除

  • 参数描述 path
  • bool
console.log(file.Remove("D:\\Go\\xxx\\xx\\xx\\xx\\"))

获取文件夹所有的文件或者文件夹

  • 参数描述 path
  • Array {"FileName":"**","IsDir":true}
console.log(JSON.stringify(file.ListFile("C:\\Users\\hxm\\Desktop\\test\\")))

复制文件或者文件夹下所有文件

  • 参数描述 源路径,现路径
  • bool
console.log(file.Copy("C:\\Users\\hxm\\Desktop\\test\\y\\","C:\\Users\\hxm\\Desktop\\test\\x\\"))

按行读取文件为字符串数组

  • 参数描述 源路径
  • string[]
let datas = file.ReadLine("C:\\Users\\hxm\\Desktop\\a.txt")
for(let data of datas){
    console.log(data)
}

读取文件为字符串

  • 参数描述 源路径
  • string
console.log(file.Read("C:\\Users\\hxm\\Desktop\\a.txt"))

读取文件为字节

  • 参数描述 源路径
  • bytes
console.log(file.ReadBytes("C:\\Users\\hxm\\Desktop\\a.txt"))

写文件

  • 参数描述 文件路径,(字符串或者字节数组)
  • bool
file.Write("C:\\Users\\hxm\\Desktop\\b.txt","文件内容")

追加写文件

  • 参数描述 文件路径,(字符串或者字节数组)
  • bool
file.WriteAppend("C:\\Users\\hxm\\Desktop\\b.txt","文件内容")
1
https://gitee.com/heixiaomas_admin/hsp.git
git@gitee.com:heixiaomas_admin/hsp.git
heixiaomas_admin
hsp
hsp
master

搜索帮助