Replies: 0 comments 2 replies
|
Only works if the source and target are on the same mount / file system. |
0 replies
|
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. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
How to use 'fs. rename' to rename a file name include '/'
All reactions