@echo off不起作用

时间:2018-06-25 06:46:57

标签: batch-file echo

我目前正在研究一个项目,通过该项目我可以自动备份用户数据。我做了两个版本。一种用英语,一种用德语。经过一些编码后,我意识到命令@echo off对德语版本不再有任何影响。我在干什么? 用Notepad ++和批处理作为语言编写代码

在运行德语版本的情况下,它将如下所示: D:\ bin>在DataTrans中回显Willkommen Willkommen bei DataTrans

@echo off
title DataTrans Version 3.0

:main
cls
echo Willkommen bei DataTrans
echo Die einfache Art, Benutzerdaten zu kopieren.
echo.
echo Dieses Programm wird automatisch den angemeldeten Benuzer als Zielbenutzer erfassen.
echo.
echo Was willst du tun?
echo ---------------------------
echo [1] Benutzerdaten sichern
echo [2] Benutzerdaten wiederherstellen
echo [3] Einzelnes Backup entfernen
echo [4] Alle Backups entfernen
echo [5] Was wird gespeichert?
echo ---------------------------
set /p c=Waehle 1-5:
if %c%==1 goto backup
if %c%==2 goto restore
if %c%==3 goto del-user
if %c%==4 goto del-all
if %c%==5 goto help
cls
echo Dieser Taste wurde keine Funktion zugeordnet.
echo Bitte versuchen sie es erneut.
pause
goto main

:backup
cls
echo Willkommen im Backup-Bereich
echo ------------------------------------------------------
echo Bitte benenne dein Backup, um spaeter verwechslungen
echo zu vermeiden
echo.
echo Hinweis:
echo Bitte merke dir deinen Backup Namen, um ihn später
echo wiederherzustellen.
echo ------------------------------------------------------
set /p bckup=Neues Backup heisst:
cls
echo ------------------------------------------------------
echo Backup wird nach Countdown ausgefuehrt.....
echo ------------------------------------------------------
timeout /t 3 /nobreak
robocopy C:\Users\%username%\Desktop %~d0\userdata\%bckup%\Desktop *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Desktop\Desktop.ini
robocopy c:\Users\%username%\Documents %~d0\userdata\%bckup%\Documents *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Documents\Desktop.ini
robocopy c:\Users\%username%\Downloads %~d0\userdata\%bckup%\Downloads *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Downloads\Desktop.ini
robocopy c:\Users\%username%\Favorites %~d0\userdata\%bckup%\Favorites *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Favorites\Desktop.ini
robocopy c:\Users\%username%\Music %~d0\userdata\%bckup%\Music *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Music\Desktop.ini
robocopy c:\Users\%username%\Pictures %~d0\userdata\%bckup%\Pictures *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Pictures\Desktop.ini
robocopy c:\Users\%username%\Videos %~d0\userdata\%bckup%\Videos *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Videos\Desktop.ini
cls
echo ------------------------------------------------------
echo Backup wurde erstellt!
echo ------------------------------------------------------
echo Weiterleitung zur Startseite in:
timeout /t 5 /nobreak
goto main

:restore
cls
echo Willkommen im Wiederherstellungs-Bereich
echo ------------------------------------------------------------------------
echo Bitte gib den Namen deines gewünschten Backups ein
echo.
echo Hinweis:
echo Der Backup Name muss genau so geschreiben werden wie er erstellt wurde.
echo ------------------------------------------------------------------------
set /p restr=Name des Backups:
cls
echo ------------------------------------------------------
echo Wiederherstellung wird nach Countdown ausgefuehrt.....
echo ------------------------------------------------------
timeout /t 3 /nobreak
robocopy %~d0\userdata\%restr%\Desktop C:\Users\%username%\Desktop *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Documents c:\Users\%username%\Documents *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Downloads c:\Users\%username%\Downloads *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Favorites c:\Users\%username%\Favorites *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Music c:\Users\%username%\Music *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Pictures c:\Users\%username%\Pictures *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Videos c:\Users\%username%\Videos *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
echo.
cls
echo ------------------------------------------------------------------------
echo Wiederherstellung erfolgreich abgeschlossen!
echo ------------------------------------------------------------------------
echo Weiterleitung zur Startseite in:
timeout /t 5 /nobreak
goto main

:del-user
echo Willkommen zum Backup-loesch-Bereich
echo ------------------------------------------------------------------------
echo Welches Backup sollte von dem USB-Stick entfernt werden?
echo ------------------------------------------------------------------------
set /p del=Zu loeschendes Backup:
cls
rmdir %~d0\userdata\%del%\ /s /q
echo ------------------------------------------------------------------------
echo Backup wurde gelöscht.
echo ------------------------------------------------------------------------
echo Weiterleitung zur Startseite in:
timeout /t 5 /nobreak
goto main

:del-all
cls
echo Willkommen zum USB-Entleerungs-Beriech
echo ------------------------------------------------------------------------
echo Bist du sicher das du alle Backups entfernen moechtest?
echo ------------------------------------------------------------------------
set /p delall=Tippe "DELETE" zur Bestaetigung:
if %delall%==DELETE goto del-all2
cls
echo Entschuldigung, Diese Eingabe ist ungueltig.
echo Bitte versuche es erneut!
timeout /t 4 /nobreak
goto del-all

:del-all2
cls
echo ------------------------------------------------------------------------
echo Loeschvorgang nach Countdown.......
echo ------------------------------------------------------------------------
timeout /t 5 /nobreak
del /q "%~d0\userdata\*"
FOR /D %%p IN ("C:\Temp\*.*") DO rmdir "%%p" /s /q
cls
echo ------------------------------------------------------------------------
echo Loeschvorgang abgeschlossen!
echo ------------------------------------------------------------------------
echo Weiterleitung zur Startseite:
timeout /t 5 /nobreak
goto main

:help
cls
echo Willkommen zum Hilfe-Bereich
echo ------------------------------------------------------------------------
echo Folgende Ordner Werden mithilfe von DataTrans gesichert:
echo.
echo Desktop
echo Dokumente
echo Downloads
echo Internet Explorer Favoriten
echo Musik
echo Bilder
echo ------------------------------------------------------------------------
pause
goto main

英语版本供比较:

@echo off
title DataTrans version 3.0

:main
cls
echo Welcome to DataTrans
echo The easy way to copy user data from one pc to another
echo.
echo This Programm will automatically choose the Account that is currently 
echo logged in.
echo.
echo What would you like to do?
echo ---------------------------
echo [1] Backup User-Data
echo [2] Restore User-Data
echo [3] Delete Specific Backup
echo [4] Delete all saved Backups from USB-Stick
echo ---------------------------
set /p c=Select between 1 and 5:
if %c%==1 goto backup
if %c%==2 goto restore
if %c%==3 goto del-user
if %c%==4 goto del-all
cls
echo This character is not listed in the menu
echo Please try a different one.
pause
goto main

:backup
cls
echo Welcome to the Backup-section
echo ------------------------------------------------------
echo Please give your Backup a name to make sure you won't
echo restore the wrong data later.
echo.
echo Disclaimer:
echo Please remember the backup name. You will need it to
echo restore your Data later.
echo ------------------------------------------------------
set /p bckup=Give it a name:
cls
echo Backup will be starting in:
timeout /t 3 /nobreak
robocopy C:\Users\%username%\Desktop %~d0\userdata\%bckup%\Desktop *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Desktop\Desktop.ini
robocopy c:\Users\%username%\Documents %~d0\userdata\%bckup%\Documents *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Documents\Desktop.ini
robocopy c:\Users\%username%\Downloads %~d0\userdata\%bckup%\Downloads *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Downloads\Desktop.ini
robocopy c:\Users\%username%\Favorites %~d0\userdata\%bckup%\Favorites *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Favorites\Desktop.ini
robocopy c:\Users\%username%\Music %~d0\userdata\%bckup%\Music *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Music\Desktop.ini
robocopy c:\Users\%username%\Pictures %~d0\userdata\%bckup%\Pictures *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Pictures\Desktop.ini
robocopy c:\Users\%username%\Videos %~d0\userdata\%bckup%\Videos *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD c:\Users\%username%\Videos\Desktop.ini
cls
echo ------------------------------------------------------
echo Backup is complete!
echo ------------------------------------------------------
echo going back to home in:
timeout /t 5 /nobreak
goto main

:restore
cls
echo Welcome to the restore section
echo ------------------------------------------------------------------------
echo Please enter the name of the Backup you want to restore
echo.
echo Disclaimer:
echo If you enter a wrong backup name the programm won't do any changes on 
echo your data.
echo ------------------------------------------------------------------------
set /p restr=Backup name:
robocopy %~d0\userdata\%restr%\Desktop C:\Users\%username%\Desktop *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Documents c:\Users\%username%\Documents *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Downloads c:\Users\%username%\Downloads *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Favorites c:\Users\%username%\Favorites *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Music c:\Users\%username%\Music *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Pictures c:\Users\%username%\Pictures *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
robocopy %~d0\userdata\%restr%\Videos c:\Users\%username%\Videos *.* /E /MIR /SEC /SECFIX /DCOPY:T /R:1 /W:1 /XD Desktop.ini
echo.
cls
echo ------------------------------------------------------------------------
echo Restore complete. Check the Explorer to make sure everything is in 
echo order.
echo ------------------------------------------------------------------------
echo Going back to home in:
timeout /t 5 /nobreak
goto main

:del-user
echo Welcome to the Backup-Erasing section
echo ------------------------------------------------------------------------
echo Please enter the name of the backup you want to get rid off
echo ------------------------------------------------------------------------
set /p del=Backup Name:
cls
rmdir %~d0\userdata\%del%\ /s /q
echo ------------------------------------------------------------------------
echo Backup has been deleted.
echo ------------------------------------------------------------------------
echo going back to home in:
timeout /t 5 /nobreak
goto main

:del-all
cls
echo Welcome to the USB-Data erasing section
echo ------------------------------------------------------------------------
echo Are you sure you want to delete all backups from the usb stick?
echo ------------------------------------------------------------------------
set /p delall=Type "DELETE" for confirmation:
if %delall%==DELETE goto del-all2
cls
echo Sorry, this is not the right Confirmation phrase
echo please try again!
timeout /t 4 /nobreak
goto del-all

:del-all2
cls
echo ------------------------------------------------------------------------
echo Erasing after countdown.......
echo ------------------------------------------------------------------------
timeout /t 5 /nobreak
del /q "%~d0\userdata\*"
FOR /D %%p IN ("C:\Temp\*.*") DO rmdir "%%p" /s /q
cls
echo ------------------------------------------------------------------------
echo Erasing completed Successfully!
echo ------------------------------------------------------------------------
echo going back to home in:
timeout /t 5 /nobreak
goto main

:help
cls
echo Welcome to the help-section
echo ------------------------------------------------------------------------
echo Following folders will be saved using DataTrans:
echo.
echo Desktop
echo Documents
echo Downloads
echo Internet Explorer Favorites
echo Music
echo Pictures
echo ------------------------------------------------------------------------
pause
goto main

1 个答案:

答案 0 :(得分:5)

一个简化的示例会很好,您只需两行即可演示您的问题。
没有“ CLS”命令,您就已经找到问题了。

D:\Bin>´╗┐@echo off
Der Befehl "´╗┐@echo" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

顺便说一句。您应使用“ ANSI编码”而不是“带BOM的UTF8”保存德语版本