How to use the renameSync function from fs
Find comprehensive JavaScript fs.renameSync code examples handpicked from public code repositorys.
93 94 95 96 97 98 99 100 101 102
let srcFilePath = path.join(src, entry), destFilePath = path.join(dest, entry); if (entry === 'favicon.ico') { // Skip it. } else if (entry !== 'index.html') { fs.renameSync(srcFilePath, destFilePath); } else { copyIndex(srcFilePath, dest); } }
54
268
0
GitHub: blockcollider/bcnode
78 79 80 81 82 83 84 85 86 87
exports.readlink = co.promisify(fs.readlink); exports.readlinkSync = fs.readlinkSync; exports.realpath = co.promisify(fs.realpath); exports.realpathSync = fs.realpathSync; exports.rename = co.promisify(fs.rename); exports.renameSync = fs.renameSync; exports.rmdir = co.promisify(fs.rmdir); exports.rmdirSync = fs.rmdirSync; exports.stat = co.promisify(fs.stat); exports.statSync = fs.statSync;
22
45
26
GitHub: riwsky/bucklescript
38 39 40 41 42 43 44 45 46
* @param {string} from * @param {string} to */ function poor_copy_sync(from,to){ console.log(from , '----->', to) fs.renameSync(from,to) // fs.renameSync(from,to) }
424
0
2
+ 5 other calls in file
42 43 44 45 46 47 48 49 50
* @param {string} from * @param {string} to */ function poor_copy_sync(from, to) { console.log(from, '----->', to) fs.renameSync(from, to) // fs.renameSync(from,to) }
10
243
17
+ 5 other calls in file
293 294 295 296 297 298 299 300 301 302
}, _housekeepingSync: function (outputFileFolderWithoutSlash, outputFileName) { const tempFilePath = `${tempDir}/${outputFileName}`; if (fs.existsSync(tempFilePath)) { fs.renameSync(tempFilePath, `${outputFileFolderWithoutSlash}/${outputFileName}`); fs.readdirSync(outputFileFolderWithoutSlash).forEach((foundFile) => { if (foundFile !== outputFileName) { fs.unlinkSync(`${outputFileFolderWithoutSlash}/${foundFile}`); }
51
157
10
+ 12 other calls in file
298 299 300 301 302 303 304 305 306 307 308 309
const destFile = path.join(tmpdir.path, 'foo'); fs.rename(nonexistentFile, destFile, common.mustCall(validateError)); assert.throws( () => fs.renameSync(nonexistentFile, destFile), validateError ); }
42
19
0
+ 3 other calls in file
GitHub: Giftia/ChatDACS
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
app.post("/upload/image", upload.single("file"), function (req) { logger.info("用户上传图片".log); logger.info(req.file); const oldname = req.file.path; const newname = req.file.path + path.parse(req.file.originalname).ext; fs.renameSync(oldname, newname); io.emit("picture", { type: "picture", content: `/uploads/${req.file.filename}${path.parse(req.file.originalname).ext}` }); });
19
62
4
418 419 420 421 422 423 424 425 426 427
renameFile(id_old, id_new) { try { const path_old = USERDATA_PATH + id_old + ".svg"; const path_new = USERDATA_PATH + id_new + ".svg"; fs.renameSync(path_old, path_new); this.log("Icon reamed: from "+path_old+" to"+path_new); } catch(error) { this.log("Error renaming device icon: "+path_old+" to"+path_new); }
6
5
3
81 82 83 84 85 86 87 88 89 90 91 92
const unlinkFileSync = path => { if (!isWindows) return fs.unlinkSync(path) const name = path + '.DELETE.' + crypto.randomBytes(16).toString('hex') fs.renameSync(path, name) fs.unlinkSync(name) } // this.gid, entry.gid, this.processUid
3
2
0
GitHub: AxelRothe/wranglebot
588 589 590 591 592 593 594 595 596 597
* * @param pathToElement * @param newFolder */ move(pathToElement, newFolder) { return fs.renameSync(pathToElement, this.join(newFolder, this.basename(pathToElement))); } /** * Rename a file and move it, returns true if the file was moved
0
4
2
+ 2 other calls in file
GitHub: emodamage/node_api
496 497 498 499 500 501 502 503 504 505
// body [Object: null prototype] { test: 'test1111' } let file = req.files[0] let path = 'public/image/' + username + '.' + file.originalname.split('.')[1] // 覆盖 fs.renameSync('./public/image/' + file.filename, path); let fileInfo = {} fileInfo.type = file.mimetype fileInfo.name = file.originalname
0
2
1
+ 2 other calls in file
496 497 498 499 500 501 502 503 504 505
retry_download = false; let f = files[0]; console.log('rename downloaded subtitle file -->' + f); let newName = f.replace(/\(|\)|\'|\s+|-/g, ''); console.log('new file name -->' + newName); fs.renameSync(download_dir + f, download_dir + newName); let output_file = download_dir + newName + '.2.srt'; fs.access(output_file, (err) => { if (!err) { console.log('output file exists, remove it');
0
0
1
236 237 238 239 240 241 242 243 244 245
}); } else { // video content newPathStr = `uploads/${user}/${req.files[i].filename}`; fs.renameSync(oldPath, newPathStr, function (err) { if (err) throw err; newPath.push(newPathStr); }); if (typeof req.files !== 'undefined') {
0
0
1
305 306 307 308 309 310 311 312 313 314
); // Write to file const REPLAY_JSON = JSON.stringify(REPLAY, undefined, 2); fs.writeFileSync(workFile, REPLAY_JSON); fs.renameSync(`replays/${file}.replay`, `replays/processed/${file}.replay`); execSync( `bin\\rattletrap-12.0.1-windows.exe -m encode -i "${workFile}" -o "replays/out/${file}.anonymous.replay"` );
0
0
1
8 9 10 11 12 13 14 15 16 17
} else { const { originalname, path } = req.file; const parts = originalname.split("."); const ext = parts[parts.length - 1]; const newPath = path + "." + ext; fs.renameSync(path, newPath); const { token } = req.cookies; jwt.verify(token, secret, {}, async (err, info) => { if (err) throw err;
0
0
1
+ 7 other calls in file
GitHub: pb-it/wing-cms-api
805 806 807 808 809 810 811 812 813 814
if (fileName) { if (old && old[str] && old[str] != fileName) { var oldFile = path.join(localPath, old[str]); var newFile = path.join(localPath, fileName); if (fs.existsSync(oldFile) && !fs.existsSync(newFile)) fs.renameSync(oldFile, newFile); } } else { if (old && old[str]) { var file = path.join(localPath, old[str]);
0
0
1
97 98 99 100 101 102 103 104 105
binaryFileName = 'direcbase'; break; } const executablePath = path.resolve(__dirname, '../lib/',binaryFileName); fs.renameSync( path.join(projectDir, 'env.sample'), path.join(projectDir, '.env') );
0
0
0
fs.readFileSync is the most popular function in fs (2736 examples)