-1

I have started to use ROBOCOPY command a lot. I use ROBOCOPY source destination /MIR. Is there any way to add confirmation, "y/n" after the command is executed, but not actually ran. So I will type ROBOCOPY source destination /MIR and after I press enter there will be are you sure yes/no confirmation box. In that way if the command is executed by accident I can still stop it.

EDIT

I tried with .bat files, but can't figure out how to run confirmation after command is ran, I mean after I press enter on the keyboard to run ROBOCOPY and before ROBOCOPY actually run, so it pauses the command until I press y or n.

For cmd command that is so powerful they should add a flag to enable/disable this functionality.

EDIT

I can see that this is causing a big confusion, so let me explain how it should run:

C:> name_of_batch_file.bat source destination

{enter}

C:> are you sure y/n

{y}

C:>

3
  • This is impossible, unless you're willing to replace robocopy by a .bat file (that is not called "robocopy").
    – harrymc
    Commented Mar 20 at 20:24
  • @harrymc yes, I'm OK with that. Any solution is OK by me
    – IGRACH
    Commented Mar 20 at 21:34
  • to your edit: the idea is to make a batch file that asks first and then runs the robocopy process. If you want a dynamic one, you would capture the command line parameters and call robocopy using the passed parameters. ss64.com/nt/syntax-args.html
    – Yorik
    Commented Mar 20 at 21:47

2 Answers 2

1

What you want is not directly possible.

What you CAN do is write a script that takes your input, presents the confirmation prompt, and then runs robocopy to complete the actions.

PowerShell can do this pretty easily. Here's something that could work:

Param (
    [Parameter(Mandatory = $true)]
    [string] $SourcePath,
    [Parameter(Mandatory = $true)]
    [string] $DestinationPath
)

Write-host "You want to MIRROR the contents of $SourcePath to $DesinationPath"
$confirmation = Read-Host "Please confirm this is what you want to do: y/n"

If($confirmation -eq "y") {
    ROBOCOPY $SourcePath $DesinationPath /MIR
}
Else {
    Write-Host "The process has been declined."
}

You'd need to enclose any paths with non-standard characters or spaces in quotes, but this will take the two paths you give as arguments, prompt you to confirm this is what you want to do, and if you respond with "y" it will complete the action.

2
  • I need it in cmd
    – IGRACH
    Commented Mar 20 at 23:41
  • I don't do cmd. Regardless, this illustrates the SORT of thing you could do in batch/cmd. Commented Mar 21 at 0:18
0

Asking for a return entry is done using the SET command.

A simple test example is:

@echo Off
set /p "ans=are you sure y/n - "

if "%ans" equ "y" (
  echo you said y 
) else (
  echo you said n
)

You must log in to answer this question.

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