traxtormer
Goto Top

Bei Abfrage einer Variablen Absturz des Batchs

Hallo Leute,

dieses Batch soll alle Dateien (ohne Ausnahme) von der WinXP-CD in einen lokalen Ordner kopieren. Natürlich soll das Batch nicht einfach blind weiter laufen oder abbrechen, wenn keine CD gefunden wird.

bin leider nicht so batch gewandt und wollte 1.) wissen, ob man an diesem Code was verbessern (abkürzen, vereinfachen) kann, oder ob der so halbwegs ok ist.
2.) Wenn ich bei der unteren Abfrage (if %WIN%.....) eine Leertaste eingebe, stürzt mir das ganze Batch ab.

(nircmd ist ein kleines Programm mit ein paar kleinen Tools, wie z.B.: CD-fach öffnen,...)

Bitte helft mir in der Sache.

echo Copy WinXP-Files!
echo Copy WinXP-Files! >> C:\Log.txt

if exist "C:\INSTALL\i386" goto available_win  
nircmd.exe cdrom open D: 
:beg_win
echo Please insert the Windows XP Prof. Disc and press a key!

If not Exist "D:\i386" goto sta_win  
xcopy "D:\" "C:\INSTALL\i386\" /E /V /H  
if errorlevel 0 goto success_win else goto error_win

:error_win
echo Copying of the XP files was not successful! %date% %time% >> C:\Log.txt
echo Copying of the XP files was not successful!
goto end_win

:available_win
echo Copying of the Windows files was omitted because the listing already exists! %date% %time% >> C:\Log.txt
echo Copying of the Windows files was omitted because the listing already exists!
goto end_win

:sta_win
echo Please put in the right Windows XP Prof. Disc! %date% %time% >> C:\Log.txt
echo Please put in the right Windows XP Prof. Disc!
set /p WIN=If you want to repeat the copying, press "y", if you want to continue without copying the files press "n" and "Enter"!  
If %WIN%==n goto error_win
If %WIN%==y goto beg_win
echo The key you typed in was wrong! Please enter a correct one!
goto sta_win


:success_win 
echo Copying of the XP files was successful! %date% %time% >> C:\Log.txt
echo Copying of the XP files was successful!

:end_win
.
.
.
.
.


Danke im Voraus.

LG

Content-Key: 148744

Url: https://administrator.de/contentid/148744

Ausgedruckt am: 28.03.2024 um 19:03 Uhr

Mitglied: t-roc
t-roc 11.08.2010 um 08:35:53 Uhr
Goto Top
Hi, kann es sein das es daran liegt, dass du der Variable %WIN% schon etwas zuweist?
Versuch es mal so:

ECHO If you want to repeat the copying, press "y", if you want to continue without copying the files press "n" and "Enter"!
set /p WIN=
If %WIN%==n (goto error_win)
If %WIN%==y (goto beg_win)

Is aber auch nur eine Vermutung.

Jedenfals hab ich es so in einer Batch von mir gemacht, die is aber auch schon ein paar Jahre alt. face-smile

Gruß
Tobias
Mitglied: Traxtormer
Traxtormer 11.08.2010 um 09:08:33 Uhr
Goto Top
Zuerst mal danke für deine Antwort.

Nein leider. Genau das selbe.

Hmm...habe echt keine Idee wie man das Problem umgehen kann.

SG
Mitglied: Biber
Biber 11.08.2010 um 09:42:32 Uhr
Goto Top
Moin traxformer,

falls die Variable %win% leer ist würde die Anweisung
If %WIN%==n (goto error_win)
...doch aufgelöst zur Prüfung
If  ==n (goto error_win)
--> und ergibt einen Syntaxfehler.
Besser ist:
If  /i "%WIN%"=="y"  goto beg_win
If  /i "%WIN%"=="n"  goto error_win
...was syntaktisch korrekt aufgelöst wird zu

If  /i ""=="y"  goto beg_win
If  /i ""=="n"  goto error_win

Der zusätzliche Schalter "/i" ist Spielerei/nicht wesentlich für den Syntaxfehler.
Der sagt nur: Unterscheide nicht zwischen Klein- und Grossschreibung.

Grüße
Biber
Mitglied: Traxtormer
Traxtormer 11.08.2010 um 10:28:17 Uhr
Goto Top
Dankeschön für die schnelle Hilfe.

PS: Ich finde dieses Board einfach super.