Replies: 0 comments 2 replies
-
Only works if the source and target are on the same mount / file system. |
Beta Was this translation helpful? Give feedback.
-
You can try using the const fs = require('fs');
const path = require('path');
const oldFilePath = 'path/to/old/file/with/slash.txt'; // Example old file path with '/'
const newFileName = 'new_file_name.txt'; // Example new file name without '/'
const dirname = path.dirname(oldFilePath);
const newFilePath = path.join(dirname, newFileName);
fs.rename(oldFilePath, newFilePath, (err) => {
if (err) {
console.error('Error renaming file:', err);
} else {
console.log('File renamed successfully');
}
}); In this example, we're using the Make sure to replace If you're still encountering issues, please provide more details about the problem you're facing so that I can assist you further. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How to use 'fs. rename' to rename a file name include '/'
Beta Was this translation helpful? Give feedback.
All reactions