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);
    }
}
fork icon54
star icon268
watch icon0

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;
fork icon22
star icon45
watch icon26

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)

}
fork icon424
star icon0
watch icon2

+ 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)

}
fork icon10
star icon243
watch icon17

+ 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}`);
      }
fork icon51
star icon157
watch icon10

+ 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
  );
}

fork icon42
star icon19
watch icon0

+ 3 other calls in file

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}`
  });
});
fork icon19
star icon62
watch icon4

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);
    }
fork icon6
star icon5
watch icon3

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
fork icon3
star icon2
watch icon0

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
fork icon0
star icon4
watch icon2

+ 2 other calls in file

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
fork icon0
star icon2
watch icon1

+ 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');
fork icon0
star icon0
watch icon1

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') {
fork icon0
star icon0
watch icon1

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"`
);
fork icon0
star icon0
watch icon1

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;
fork icon0
star icon0
watch icon1

+ 7 other calls in file

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]);
fork icon0
star icon0
watch icon1

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')
);
fork icon0
star icon0
watch icon0