0

I'm working on a simple tool that copies files to and from desired locations and I want to replace the print in the CLI with a message of my choosing, I've looked around and so far all solutions I've found don't implement what I'm looking for. Here is a snippet of my code:

@ECHO OFF
ECHO D | XCOPY "%USERPROFILE%\Documents\Visual Studio 2017\Code Snippets" ".\Backup\Code Snippets" /s /q /y
ECHO D | XCOPY "%USERPROFILE%\Documents\Visual Studio 2017\Projects" ".\Backup\Projects" /s /q /y
ECHO D | XCOPY "%USERPROFILE%\Documents\Visual Studio 2017\Templates" ".\Backup\Templates" /s /q /y

I want to make a message display something like "Backup in progress..." instead of each operation showing. I have tried combinations of PRINT, ECHO, and even CLS to replace the window contents but I can't get it to work. What am I missing? I have seen other batch scripts do this (which I no longer have to take notes from) and would like to do the same.

2 Answers 2

2

Added a redirection of your choosing at the end that isn't on the STDOUT. For example >nul or >file.txt and corresponding echo statements. You won't be able to show progress during the execution of xcopy that way.

echo "Copy in progress"
xcopy > nul
echo "Copy finished"

Error handling etc. might be more complicated that way.

0
2

Use

  1. the @ command prefix to avoid showing a single command;
  2. echo off to avoid showing all future commands (until re-enabled).

This is most commonly combined into an @echo off as the very first thing in your script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .