本文整理汇总了TypeScript中fs.rename函数的典型用法代码示例。如果您正苦于以下问题:TypeScript rename函数的具体用法?TypeScript rename怎么用?TypeScript rename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rename函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: HttpError
var promises = files.map((file)=> {
var guid
if (body.info) {
var info = JSON.parse(body.info)
if (info.guid) {
if (!info.guid.match(/[\w\-]+/))
throw new HttpError('Invalid guid: ' + info.guid + '.', 400)
guid = info.guid
}
}
guid = guid || uuid.v1()
var path = require('path')
var ext = path.extname(file.originalname) || ''
var filename = guid + ext
var filepath = (this.config.paths.files) + '/' + filename
var fs = require('fs')
fs.rename(file.path, filepath);
// !!! Add check if file already exists
return this.ground.update_object('file', {
guid: guid,
name: filename,
path: file.path,
size: file.size,
extension: ext.substring(1),
status: 1
}, user)
})
示例2: function
fs.readdirSync(src).forEach(function (childItemName) {
fs.rename(
path.resolve(src, childItemName),
path.resolve(src, childItemName.replace("project", projectName)), function (e) {
if (e) throw e;
});
});
示例3: reject
return new Promise<void>((resolve, reject) => {
fs.rename(oldName, newName, err => {
if (err) {
return reject(err);
}
return resolve();
});
});
示例4: Promise
const promise = new Promise((resolve, reject) => {
fs.rename(filePath, newFilePath, (err: NodeJS.ErrnoException) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
示例5: reject
return new Promise<void>((resolve, reject) => {
fs.rename(from, to, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
示例6: function
const promise = new Promise<void>(function(resolve, reject) {
fs.rename(src, dest, function(err) {
if (err) {
reject(err.code);
} else {
resolve();
}
});
});
示例7: Promise
return new Promise((resolve, reject) => {
fs.rename(oldPath, newPath, (err: any) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
示例8: onFileReadFunction
fs.readFile(__path__, 'utf-8', (err, _) => {
if (err) throw err;
const pathStart = filename.split('.')[0];
if (pathStart === '') throw err;
fs.rename(__path__, onFileReadFunction(dirname + pathStart), err => {
if (err) throw err;
console.log(`Renamed ${filename} to ${onFileReadFunction(dirname + pathStart)}`);
});
});
示例9:
fs.stat(oldDirPath, (err, stats) => {
const dirPath = path.join(this.server.projectPath, `assets/${this.server.data.entries.getStoragePathFromId(id)}`);
if (stats == null) asset.load(dirPath);
else {
fs.rename(oldDirPath, dirPath, (err) => {
if (err != null) throw err;
asset.load(dirPath);
});
}
});
示例10: uploadFile
async uploadFile(ctx: k.IContext, next) {
let file = ctx.req['file'];
let originalname = path.parse(file.originalname);
let newname = originalname.name + '.' + UUID.raw() + originalname.ext;
let filepath = file.path;
let newpath = 'files/' + newname;
fs.rename(filepath, newpath);
ctx.set('Content-Type', 'application/json');
ctx.set('status', 200);
ctx.body = { fileUri: newpath };
}