Commit 9f3dbea3 authored by Scott Sun's avatar Scott Sun

scott

parent d9945c0f
var fs = require('fs');
var _ = require('lodash')
// 打开一个文本文件 返回文件流
print(fs.openFile('./test.md', 'ra'))
// 打开一个二进制文件 返回文件流
print(fs.openRawFile('./test.md', 'ra'))
// 更改文件权限 返回布尔值 linux文件权限 777
print(fs.chmod('./test.md', 777) )
// 复制文件 文件路径 目标路径 是否覆盖
print(fs.copyFile('./test.md', './copy/test.md'))
// 判断文件或者文件夹是否存在
print(fs.exists('./test.md'));
print(fs.exists('./copy2'));
// 只判断文件 && 只判断文件夹
// fs.fileExists fs.dirExists
// 创建硬链接 return boolean
print(fs.link('./test.md','./copy/test.md'))
// 获取文件信息
console.log(fs.stat('./test.md'))
// 创建文件夹
fs.mkdir('./temp')
// 获取文件绝对路径
print(fs.realpath('./test.md'))
// 重命名或者移动 old new boolean 是否覆盖
fs.rename('./test2.md','./temp/test.md')
// 删除文件夹 path boolean默认空文件删除 true强制删除
fs.rmdir('./dele', true)
// 删除文件
fs.unlink('./haha.md')
// 获取文件夹下的文件信息列表 dirpath 递归查找级别 -1表示无限 表示子文件不会的key
var filelist = fs.listDir('../fs')
for(i=0;i<filelist.length;i++){
print(_.toString(filelist[i]))
}
// 读取文本文件的内容
print("读取文本文件的内容")
print(fs.readFile('./test.md'))
// 写入 go go go
fs.writeFile('./test.md','\ngo!go!go!',{
encoding:'UTF-8',
append:true,
withbom:false
})
// 获取操作系统临时目录
print(fs.tmpdir())
// 获取操作系统当前用户HOME目录
print(fs.homedir())
\ No newline at end of file
# title
go!go!go!
go!go!go!
go!go!go!hahaha
\ No newline at end of file
var fs = require('fs')
// 获取文件流
var file = fs.openFile('./test.md','ra')
// 设置文件编码
file.setCodec('UTF-8')
// 获取文件编码
print(file.codec())
// 设置自动检测Unicode
file.setAutoDetectUnicode(true)
// 是否自动检测Unicode
print(file.isAutoDetectUnicode())
// 设置是否添加编码BOM
file.setGenerateByteOrderMark(true);
// 检测 !!文档错误
print(file.isGenerateByteOrderMark())
// 设置是否每次在写入文件时自动刷新缓存至文件
file.setAutoFlush(false);
// 检测
print(file.isAutoFlush())
// 是否读取到文件结尾
print(file.atEnd())
// 将文件读取位置重置
file.reset();
// 刷新缓存至文件
file.flush();
// 寻找文件读取位置
print(file.seek(0))
// 获取当前文件读取位置
print(file.pos())
// 设置自动忽略空格
file.skipWhiteSpace()
// 读取一行
print(file.readLine());
// 读取全部文件内容
print(file.readAll());
// 读取指定大小文本块
print(file.read(1));
// 写入文件 如果打开了自动缓存 aotoflush就不需要close
file.write("hahaha")
file.close()
\ No newline at end of file
module.exports = function(){
console.log("test")
}
\ No newline at end of file
{
"name": "@scott/demo",
"version": "1.0.0",
"description": "demo",
"engines": {
"topjs": ">= 3.0.2"
},
"dependencies": {}
}
\ No newline at end of file
var os = require("os")
// arch() 打开一个文本文件或者获取操作系统位数
print(os.arch())
// hostname() 返回计算机主机名
print(os.hostname())
// networkInterfaces() 返回计算机网卡信息
print(os.networkInterfaces())
// tmpdir() 获取操作系统临时目录
print(os.tmpdir())
// homedir() 获取用户目录
print(os.homedir())
// type() 获取操作系统类型
print(os.type())
// kernelType() 获取操作系统内核类型
print(os.kernelType())
// kernelVersion() 获取操作系统内核版本
print(os.kernelVersion())
// version() 获取操作系统版本
print(os.version())
// name() 获取操作系统名称 prettyName() 获取操作系统名称2
print(os.name())
print(os.prettyName())
// getNow() 获取当前时间
print(os.getNow())
// getToday() 获取操作系统日期
print(os.getToday())
// 通过全局变量__package__可以获取到包管理对象;
print(__package__.libraryPaths())
// 添加包目录 addLibraryPath(path)
__package__.addLibraryPath('../myPkg')
print(__package__.libraryPaths())
var demo = require('demo')
demo()
// __package__.setLibraryPaths(['C:/MyTopJsPackages','C:/topJs/topjs3/topjs_modules']) 设置包路径
\ No newline at end of file
// topjsBinPath() 获取topjs执行文件路径
var process = require('process')
print(process.topjsBinPath())
// pid() 获取当前进程的PID号;
print(process.pid())
// platform() 获取平台名称
print(process.platform())
// evalFileDir() 获取当前执行的脚本文件路径
print(process.evalFileDir())
// evalFileName() 同上 获取文件名
print(process.evalFileName())
// evalFileBaseName() 同上去除后缀
print(process.evalFileBaseName())
// 创建一个事件变量
var event = process.createEvent()
print(event)
// getEnv() 获取环境变量
var env = process.getEnv('path')
// print(env)
// setEnv() 获取和设置
process.setEnv('path','...')
// 立即对进程进行垃圾回收
process.gc()
// exit退出
// process.exit(0)
// mainLoop() 开始事件主循环
// process.mainLoop()
// exec() 执行外部命令
// process.execArgv('dir', ['/N', 'C:\\temp'])
// argv() 返回运行时的命令行参数
print(process.argv)
// stdout() 标准输出流
print(process.stdout)
// stdin() 标准输入流
print(process.stdin)
// stderr() 标准错误流
print(process.stderr)
\ No newline at end of file
......@@ -10,3 +10,9 @@
* api核心
1. console
2. events
3. fs
4. os 工具模块
5. package 包管理
6. process 进程
* qt模块
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment