How could I use javascript to copy C:\folderA\myfile.txt
to C:\folderB\myfile.txt
? I also have to check to make sure that myfile.txt
does not already exist in folderB
. And finally I have to then rename the new file from myfile.txt
to myfile.bak
.
I know javascript can't really be used on a local file system, but if it could be, how would I write this code as simply as possible?
in browser side you cannot access local system files.But in server side you could do it as follows.
//copyfile.js
const fs = require('fs');
// destination will be created or overwritten by default.
fs.copyFile('C:\folderA\myfile.txt', 'C:\folderB\myfile.txt', (err) => {
if (err) throw err;
console.log('File was copied to destination');
});
nodejs has to be installed on your server and then run above script as follows
node copyfile.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With