0% found this document useful (0 votes)
47 views

Batch Script - Copy Files From A Network Folder To A Local Drive

This script copies files from a network folder to a local drive while listing the copied file names in a log file. It uses dir, for, xcopy and echo commands to get a list of files, copy them, and write names to the log. The script can be customized by modifying folder and file paths.

Uploaded by

amusha1406
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)
47 views

Batch Script - Copy Files From A Network Folder To A Local Drive

This script copies files from a network folder to a local drive while listing the copied file names in a log file. It uses dir, for, xcopy and echo commands to get a list of files, copy them, and write names to the log. The script can be customized by modifying folder and file paths.

Uploaded by

amusha1406
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
You are on page 1/ 1

Here is a batch script that can be used to copy files from a network folder to a local

drive, while also listing the names of the files being copied in a separate text file:

@echo off

rem Define the path to the network folder, the local drive and log file
set networkFolder=\\server\shared\folder
set localDrive=C:\local\folder
set logFile=C:\logs\fileCopy.log

rem Create the log file if it doesn't already exist


if not exist %logFile% (
echo %logFile% does not exist. Creating file...
echo.>%logFile%
)

rem Copy the files from the network folder to the local drive
for /F "usebackq tokens=*" %%F in (`dir %networkFolder% /B`) do (
echo Copying %%F...
echo %%F >> %logFile%
xcopy %networkFolder%\%%F %localDrive%\%%F /y
)

rem Display a message indicating that the files have been copied
echo All files have been copied from %networkFolder% to %localDrive%
echo The names of the files that have been copied are listed in %logFile%

In this example, replace "server" with the name or IP address of the server that hosts
the network folder, "shared\folder" with the path to the network folder, "local\folder"
with the path to the local folder where you want to copy the files and "logs\
fileCopy.log" with the path to the log file where you want to save the list of files.

This script uses the dir command to get a list of the files in the network folder, and
the for loop to iterate through the list of files. The xcopy command is used to copy
the files from the network folder to the local drive. The /y flag is used to suppress
the prompt to confirm overwriting the file.

The script also uses the echo command to write the names of the files being copied
to the log file. It also creates the log file if it doesn't exist.

You could also use the robocopy command instead of xcopy to copy files, it's more
robust and can handle more complex scenarios.

You might also like