What is the first commandment in the computer user’s bible?
For me “copy when everything is OK” because after the disaster it is no longer necessary.
Now  befor start learnig this guide, i ask you: what you need?
– For example : “ i want to pay?” if it’s no, then read guide;
– Or : “what i need to copy?” if reply is “the dates of bank movement 2021/2022 of Italy Bank” then pay (use money and professional systems) else read this guide;
– Or still “would i like to fun wirh some code line?” if it’s yes, the read this guide.
I use a simply way for crate a copy system without pay, without problem of licenze and without strage latent secrets.
Well, let’s start by saying that some ways of doing things never die!
You are ready?
Here’s a step-by-step guide on how to create and test a batch file in Windows, including using Notepad:

1) Creating a Batch File – Open Notepad:
    – Press Windows + R to open the Run dialog box.
    – Type notepad and press Enter.
2) Write Your Batch Commands:
    – In Notepad, type the commands you want to include in your batch file.

For example:

@echo off
echo Save the World!
pause

A little off-topic note for those who have been around the world of computer science and code programming for a while. Programming and code examples have been writing the example sentence “Hello World” for maybe 100 years. I’m tired of saying “hello world”, now I want to “Save the world”.

3) Save the File with a .bat Extension:
– Click on File in the menu bar and select Save As.
– In the “Save as type” dropdown, select All Files.
– Name your file with a .bat extension, for example, “example.bat”.
– Choose a location to save the file and click Save.
4) Testing the Batch File – Locate the Batch File:
– Navigate to the location where you saved your batch file.
5) Run the Batch File:
– Double-click the batch file to run it.
– A Command Prompt window will open, and you should see the output of your commands.

6) Verify the Output:
– Check the Command Prompt window to ensure the commands executed correctly.
– If there are any errors, you can edit the batch file in Notepad and save the changes.
The game is done!

Now you are thinking “where is my system for copy my files?”. That’s right. Read next steps for learn how create a symple batch file for automatize your multi files copy.

Example copy Batch File

Here’s an example of a more complex batch file that copies files from one directory to another and logs the output.
Star working using the points 1 and 2 of last example and after type in Notepad:

@echo off
set logFileBase=C:\temp\robocopy_log
echo Starting robocopy operations...
robocopy C:\SourceFolder1 D:\DestinationFolder1 /MIR /E /XO /tee /log+:%logFileBase%_SourceFolder1.txt
if %errorlevel% neq 0 echo Error copying SourceFolder1 >> %logFileBase%_SourceFolder1.txt
robocopy C:\SourceFolder2 D:\DestinationFolder2 /MIR /E /XO /tee /log+:%logFileBase%_SourceFolder2.txt
if %errorlevel% neq 0 echo Error copying SourceFolder2 >> %logFileBase%_SourceFolder2.txt
robocopy C:\SourceFolder3 D:\DestinationFolder3 /MIR /E /XO /tee /log+:%logFileBase%_SourceFolder3.txt
if %errorlevel% neq 0 echo Error copying SourceFolder3 >> %logFileBase%_SourceFolder3.txt

robocopy C:\SourceFolder4 D:\DestinationFolder4 /MIR /E /XO /tee /log+:%logFileBase%_SourceFolder4.txt
if %errorlevel% neq 0 echo Error copying SourceFolder4 >> %logFileBase%_SourceFolder4.txt
echo Robocopy operations completed.
pause

Please pay attention to the line breaks. The image above explains what I mean.

Tips for Testing- Run as Administrator: If your batch file requires administrative privileges, right-click the batch file and select Run as administrator.
– Check for Errors: Use the pause command to keep the Command Prompt window open after the batch file runs, so you can see any error messages.
– Edit and Retry: If the batch file doesn’t work as expected, open it in Notepad, make the necessary changes, and save it again.

Explanation of Parameters

  • @echo off: Turns off the display of the command itself in the Command Prompt window.
  • set logFileBase=C:\temp\robocopy_log: Sets a base name for the log files.
  • echo Starting robocopy operations…: Displays a message indicating the start of the operations.
  • robocopy: The command used to copy files and directories.
    • C:\SourceFolder1 D:\DestinationFolder1: Specifies the source and destination directories.
    • /MIR: Mirrors a directory tree (equivalent to /E plus /PURGE).
    • /E: Copies all subdirectories, including empty ones.
    • /XO: Excludes older files (files that are not modified).
    • /tee: Displays the output on the screen as well as in the log file.
    • /log+:: Appends the output to the specified log file.
  • if %errorlevel% neq 0 echo Error copying SourceFolder1 >> %logFileBase%_SourceFolder1.txt: Checks if there was an error during the copy operation and logs an error message if there was.
  • echo Robocopy operations completed.: Displays a message indicating the completion of the operations.
  • pause: Keeps the Command Prompt window open so you can see the output.

This script will now display the output on the screen as well as log it to the specified files.
I think it can be better. If you don’t like remove te parameter.

The History

The first tool that Windows (i seem to remember in the 95 version) implemented was xcopy. Just go to cmd and type “xcopy /?” to read the guide which is much simpler than the robocopy guide (acronym for Robust Copy). Generally speaking, Xcopy also does its job. I have used it for many years. Robocopy does many more things and also implements many useful controls that xcopy does not perform. So, putting aside a bit of nostalgic attitude, I will pass you directly to the most recent and useful solution. However, below are a few lines to give you an overview of the difference between xcopy and robocopy:

Xcopy

  • Purpose: Xcopy stands for “extended copy” and is used to copy multiple files or entire directory trees from one directory to another.
  • Features:
    • Can copy files across a network.
    • Allows copying of directories and subdirectories.
    • Can exclude files based on file names and extensions.
    • Supports copying only updated files.
  • Usage: Suitable for simpler, one-time copy operations and batch scripting that is not overly sophisticated.

Robocopy

  • Purpose: Robocopy stands for “robust file copy” and is designed for more complex and large file copy operations.
  • Features:
    • Can mirror or sync directories.
    • Supports multithreading for faster copying.
    • Can resume interrupted copies.
    • Offers advanced options for copying files, directories, and even entire drives with more control and flexibility.
    • Can exclude files based on various criteria, such as age or size.
  • Usage: Ideal for more advanced and automated file copy tasks, especially when dealing with large amounts of data or complex directory structures.

In summary, while xcopy is great for simpler tasks, robocopy provides more advanced features and greater control, making it suitable for more complex and large-scale operations
If you want to learn even more, I recommend the most complete guide you can wish for. That is, the guide of the person who wrote the robocopy application.

https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy

Well at the end of this guide I would appreciate if you leave me some feedback. Before copying it into the example I tested the code and then inserted it into the example, so it works. Have an happy day.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Trending