0% found this document useful (0 votes)
1 views1 page

Program 3

The document outlines a procedure for moving files using Node.js by utilizing the 'fs' module. It details the steps to set up source and destination paths, employ the rename() method to transfer the file, and handle errors. A sample code snippet is provided, demonstrating the implementation and expected output messages for success and failure scenarios.

Uploaded by

Karthik S
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

Program 3

The document outlines a procedure for moving files using Node.js by utilizing the 'fs' module. It details the steps to set up source and destination paths, employ the rename() method to transfer the file, and handle errors. A sample code snippet is provided, demonstrating the implementation and expected output messages for success and failure scenarios.

Uploaded by

Karthik S
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

3.

Moving files from Source to Destination


Aim:
To create a [Link] code to move files from source to destination.
Algorithm:
Step 1: Start the process.
Step 2: Use the require module in [Link] to include an external module named fs which is
used to handle the file system operations.
Step 3: Create a variable named oldpath which is used to store the source path from where the
file is to be moved.
Step 4: Create a variable named newpath which is used to store the destination path where the
file is to be moved.
Step 5: Use the rename() method in fs module to move the file from source to destination.
Pass the source and destination paths as parameters to the rename() method.
Step 6: Use the error function to display the message “Error – File not moved” or display the
message “Successfully moved file”.
Step 7: Stop the process.
Coding:
var fs = require('fs')
var oldPath = "D:/New folder/[Link]"
var newPath = "D:/New folder 1/[Link]"

[Link](oldPath, newPath, function (err) {


if (err) {
[Link]("Error - File not moved")
} else {
[Link]("Successfully moved the file from Source folder to Destination folder")
}
})
Output:
Successfully moved the file from Source folder to Destination folder
Error - File not moved

You might also like