本文整理匯總了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 };
}