首页 > 解决方案 > @echo off 不起作用

问题描述

我目前正在开发一个项目,我可以使用该项目自动化备份用户数据的过程。我做了两个版本。一份英文,一份德文。经过一些编码后,我意识到该命令@echo off不再对德语版本产生任何影响。我在做什么?代码是用 Notepad++ 和 Batch 作为语言编写的

当我运行德语版本时,它看起来像这样: D:\bin>echo Willkommen bei DataTrans 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

标签: batch-fileecho

解决方案


一个简化的例子会很好,你只需要两行来证明你的问题。
如果没有您的“CLS”命令,您已经发现了问题。

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

顺便提一句。您应该使用“ANSI-Encoding”而不是“UTF8 with BOM”保存您的德语版本


推荐阅读