How can I make an “are you sure” prompt in a Windows batchfile?

前端 未结 11 1234
时光说笑
时光说笑 2020-12-07 19:43

I have a batch file that automates copying a bunch of files from one place to the other and back for me. Only thing is as much as it helps me I keep accidentally selecting t

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 20:07

    Here is a simple example which I use in a backup (.bat / batch) script on Windows 10, which allows me to have different options when making backups.

    ...
    
    :choice
    set /P c=Do you want to rsync the archives to someHost[Y/N]?
    if /I "%c%" EQU "Y" goto :syncthefiles
    if /I "%c%" EQU "N" goto :doonotsyncthefiles
    goto :choice
    
    :syncthefiles
    echo rsync files to somewhere ...
    bash -c "rsync -vaz /mnt/d/Archive/Backup/ user@host:/home/user/Backup/blabla/"
    echo done
    
    :doonotsyncthefiles
    echo Backup Complete!
    
    ...
    

    You can have as many as you need of these blocks.

提交回复
热议问题