zendara
Goto Top

Batch File funktioniert vor 10:00 nicht

Guten Morgen!

Ich habe mir ein Batch File gebastelt mit dem ich eine Datei mit 1000MB vom USB Stick auf die Festplatte kopiere und messe wie lange der Kopiervorgang dauert.
Um einen genaueren Wert zu bekommen wiederhole ich den Kopiervorgang 10x und errechne mir den Zeitlichen Durchschnittswert.
Danach wiederhole ich den ganzen Vorgang nochmal und kopiere das gleiche File von der Festplatte in einen Unterordner.

So... das ganze funktioniert eigentlich ganz gut solange es nicht vor 10 Uhr gestartet wird.

Das Problem ist, dass die Stunde keine zwei Stellen hat 9:24:03,75.
Um 10:24:03,75 habe ich dann alle Stellen zur Verfügung und es läuft alles wie gewollt.

Mit ...
 
if %timeusbstart:~0,2%==: set %timeusbstart%=0%timeusbstart% 

..wollte ich dann eine "0" in die Variable schreiben wenn die zweite Stelle von %time% ein ":" ist.

Leider ist das Ergebnis "0 9:24:03,75"

Kann mir bitte jemand weiter helfen.
 
@echo off
set xxx=xxx_1000MB.bmp
::set xxx=ipcop.iso

set log=%computername%_copytime.log
	echo Logfile: %log%
:start
set usbcopy=0
set hddcopy=0

if not exist %xxx% goto fehler

:usbcopy
set /a count=%usbcopy%+1
	echo.
	echo ###########################################
	echo      File copy in process! count: %count%/10
	echo ###########################################
	echo.

if not exist c:\copytest md c:\copytest

set timeusbstart=%time%
	echo Start copy from USB to HDD - %timeusbstart%
	
copy %xxx% c:\copytest

set timeusbend=%time%
	echo Copy from USB to HDD successful - %timeusbend%

rem ########## Hier ist der Fehler!!
	
if %timeusbstart:~0,2%==: set %timeusbstart%=0%timeusbstart%
pause
if %timeusbstart:~0,1%==0 set usbstarthour=%timeusbstart:~1,1%
if not %timeusbstart:~0,1%==0 set usbstarthour=%timeusbstart:~0,2%
if %timeusbstart:~3,1%==0 set usbstartmin=%timeusbstart:~4,1%
if not %timeusbstart:~3,1%==0 set usbstartmin=%timeusbstart:~3,2%
if %timeusbstart:~6,1%==0 set usbstartsec=%timeusbstart:~7,1%
if not %timeusbstart:~6,1%==0 set usbstartsec=%timeusbstart:~6,2%
if %timeusbstart:~9,1%==0 set usbstarthsec=%timeusbstart:~10,1%
if not %timeusbstart:~9,1%==0 set usbstarthsec=%timeusbstart:~9,2%

if %timeusbend:~0,2%==: set %timeusbend%=0%timeusbend%

if %timeusbend:~0,1%==0 set usbendhour=%timeusbend:~1,1%
if not %timeusbend:~0,1%==0 set usbendhour=%timeusbend:~0,2%
if %timeusbend:~3,1%==0 set usbendmin=%timeusbend:~4,1%
if not %timeusbend:~3,1%==0 set usbendmin=%timeusbend:~3,2%
if %timeusbend:~6,1%==0 set usbendsec=%timeusbend:~7,1%
if not %timeusbend:~6,1%==0 set usbendsec=%timeusbend:~6,2%
if %timeusbend:~9,1%==0 set usbendhsec=%timeusbend:~10,1%
if not %timeusbend:~9,1%==0 set usbendhsec=%timeusbend:~9,2%

rem startet den Test neu falls ein Stundensprung besteht
if not %usbstarthour%==%usbendhour% goto start
	echo -- %usbcopy%

goto usbstart

:usbstart
set /a usbsec = (%usbendmin%*60+%usbendsec%)-(%usbstartmin%*60+%usbstartsec%)
	echo (%usbendmin%*60+%usbendsec%)-(%usbstartmin%*60+%usbstartsec%)=%usbsec%
set /a usbhsec = %usbendhsec%-%usbstarthsec%
	echo %usbendhsec%-%usbstarthsec%=%usbhsec%
set /a usbtime = %usbsec%*100+%usbhsec%
	echo %usbsec%*100+%usbhsec%=%usbtime%

goto usbstep

:usbstep
if /I %usbcopy%==0 set usb0=%usbtime%
if /I %usbcopy%==1 set usb1=%usbtime%
if /I %usbcopy%==2 set usb2=%usbtime%
if /I %usbcopy%==3 set usb3=%usbtime%
if /I %usbcopy%==4 set usb4=%usbtime%
if /I %usbcopy%==5 set usb5=%usbtime%
if /I %usbcopy%==6 set usb6=%usbtime%
if /I %usbcopy%==7 set usb7=%usbtime%
if /I %usbcopy%==8 set usb8=%usbtime%
if /I %usbcopy%==9 set usb9=%usbtime%

if /I %usbcopy%==9 goto usbcalc
set /a usbcopy = %usbcopy%+1

goto usbcopy

:usbcalc

set /a usbtime10 = %usb0%+%usb1%+%usb2%+%usb3%+%usb4%+%usb5%+%usb6%+%usb7%+%usb8%+%usb9%
	echo usbtime10 %usb0%+%usb1%+%usb2%+%usb3%+%usb4%+%usb5%+%usb6%+%usb7%+%usb8%+%usb9%=%usbtime10%

set /a usbtime = (%usbtime10%/10)+1000000
	echo.
	echo Average Time to Copy %xxx% from USB to HDD: %usbtime:~3,2%,%usbtime:~5,2% seconds
	echo.
	
goto hddcopy

:hddcopy
set /a count=%hddcopy%+1
	echo.
	echo ###########################################
	echo      File copy in process! count: %count%/10
	echo ###########################################
	echo.

if not exist c:\copytest\hdd_to_hdd md c:\copytest\hdd_to_hdd

set timehddstart=%time%
	echo Start copy from HDD to HDD - %timehddstart%
	
copy c:\copytest\%xxx% c:\copytest\hdd_to_hdd\%xxx%

set timehddend=%time%
	echo Copy from HDD to HDD successful - %timehddend%

if %timehddstart:~0,1%==0 set hddstarthour=%timehddstart:~1,1%
if not %timehddstart:~0,1%==0 set hddstarthour=%timehddstart:~0,2%
if %timehddstart:~3,1%==0 set hddstartmin=%timehddstart:~4,1%
if not %timehddstart:~3,1%==0 set hddstartmin=%timehddstart:~3,2%
if %timehddstart:~6,1%==0 set hddstartsec=%timehddstart:~7,1%
if not %timehddstart:~6,1%==0 set hddstartsec=%timehddstart:~6,2%
if %timehddstart:~9,1%==0 set hddstarthsec=%timehddstart:~10,1%
if not %timehddstart:~9,1%==0 set hddstarthsec=%timehddstart:~9,2%

if %timehddend:~0,1%==0 set hddendhour=%timehddend:~1,1%
if not %timehddend:~0,1%==0 set hddendhour=%timehddend:~0,2%
if %timehddend:~3,1%==0 set hddendmin=%timehddend:~4,1%
if not %timehddend:~3,1%==0 set hddendmin=%timehddend:~3,2%
if %timehddend:~6,1%==0 set hddendsec=%timehddend:~7,1%
if not %timehddend:~6,1%==0 set hddendsec=%timehddend:~6,2%
if %timehddend:~9,1%==0 set hddendhsec=%timehddend:~10,1%
if not %timehddend:~9,1%==0 set hddendhsec=%timehddend:~9,2%

rem startet den Test neu falls ein Stundensprung besteht
if not %hddstarthour%==%hddendhour% goto start
	echo -- %hddcopy%
	
goto hddstart

:hddstart
	echo.
set /a hddsec = (%hddendmin%*60+%hddendsec%)-(%hddstartmin%*60+%hddstartsec%)
echo (%hddendmin%*60+%hddendsec%)-(%hddstartmin%*60+%hddstartsec%)=%hddsec%
set /a hddhsec = %hddendhsec%-%hddstarthsec%
echo %hddendhsec%-%hddstarthsec%=%hddhsec%
set /a hddtime = %hddsec%*100+%hddhsec%
echo %hddsec%*100+%hddhsec%=%hddtime%

goto hddstep

:hddstep
if /I %hddcopy%==0 set hdd0=%hddtime%
if /I %hddcopy%==1 set hdd1=%hddtime%
if /I %hddcopy%==2 set hdd2=%hddtime%
if /I %hddcopy%==3 set hdd3=%hddtime%
if /I %hddcopy%==4 set hdd4=%hddtime%
if /I %hddcopy%==5 set hdd5=%hddtime%
if /I %hddcopy%==6 set hdd6=%hddtime%
if /I %hddcopy%==7 set hdd7=%hddtime%
if /I %hddcopy%==8 set hdd8=%hddtime%
if /I %hddcopy%==9 set hdd9=%hddtime%
if /I %hddcopy%==9 goto hddcalc

set /a hddcopy = %hddcopy%+1
goto hddcopy

:hddcalc
	echo.
set /a hddtime10 = %hdd0%+%hdd1%+%hdd2%+%hdd3%+%hdd4%+%hdd5%+%hdd6%+%hdd7%+%hdd8%+%hdd9%
	echo hddtime10 %hdd0%+%hdd1%+%hdd2%+%hdd3%+%hdd4%+%hdd5%+%hdd6%+%hdd7%+%hdd8%+%hdd9%=%hddtime10%
	
rem hier wird die durchschnittliche Zeit berechnet von 10 Versuchen + 1000000 dient zusätzliche Stellen für weitere Berechnungen
set /a hddtime = (%hddtime10%/10)+1000000
	echo.
	echo Average Time to Copy %xxx% from hdd to HDD: %hddtime:~3,2%,%hddtime:~5,2% seconds
	echo.
	
goto ready

:ready
set usb=%usbtime:~3,2%,%usbtime:~5,2%
	echo Time for copy from USB to HDD %usb% seconds
set hdd=%hddtime:~3,2%,%hddtime:~5,2%
	echo Time for copy from HDD to HDD %hdd% seconds
	
goto exit

:exit
	echo -- del files
pause

del c:\copytest\%log%
del c:\copytest\%xxx%
del c:\copytest\hdd_to_hdd\%xxx%

exit

:fehler
	echo Die Datei %xxx% wurde nicht gefunden.
pause

goto exit


Danke LG
Zendara

Content-Key: 223178

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

Printed on: April 25, 2024 at 01:04 o'clock

Member: Snowman25
Snowman25 Nov 28, 2013 at 09:04:05 (UTC)
Goto Top
Hallo ,

Nimm dir doch die Stunde von time /T anstatt von %time%, dann hast du immer die führende 0.


Gruß,
@Snowman25
Member: Zendara
Zendara Nov 28, 2013 at 09:09:17 (UTC)
Goto Top
Hallo Snowman,

super danke damit wird es funktionierten! face-smile

LG
zendara
Member: bastla
bastla Nov 28, 2013 at 10:10:00 (UTC)
Goto Top
Hallo Zendara!

Alternativ könntest Du mit
set "timeusbstart=%timeusbstart: =0%"
auch (ohne Abfrage) das Leerzeichen durch 0 ersetzen.

Grüße
bastla
Member: Zendara
Zendara Nov 29, 2013 at 12:18:33 (UTC)
Goto Top
Hallo Bastla,

danke auch dir für deine Antwort. Hab etwas gebraucht bis ich herausgefunden habe wie das funktioniert.
Es sind bei Varianten von euch eingebraut und es läuft bestens.

Den Batch habe ich noch noch mit einer Dateigrössenauswertung und Übertragungsgeschwindigkeit erweiter.
Wobei ich mir bei letzteren nicht sicher bin ob das Ergebis richtig ist. Fall ich noch mehr Zeit habe muss ich nochmal alles nachrechnen.

Hier nochmal zusammenfassend den Batchinhalt fall jemand ähnliches benötigt.

cls
@echo off
rem setzt die Variable mit der gewünschten Datei
::set xxx=xxx_1000MB.bmp
set xxx=ipcop.iso

rem Auswertung der Dateigrousse in Bytes
for %%F in ("%cd%\%xxx%") do set groesse=%%~zF  
	echo %cd%\%xxx% %groesse% Bytes

rem Dateiname für ein Logfile falls benötigt
set log=%computername%_copytime.log
	echo Logfile: %log%

:start
rem Zähler startet mit 0
	echo Start Test %time% >>%log%
set usbcopy=0
set hddcopy=0

if not exist %xxx% goto fehler

	echo Start copy File from USB to HDD >>%log%
:usbcopy
set /a count=%usbcopy%+1
	echo.
	echo ###########################################
	echo      File copy in process! count: %count%/10
	echo ###########################################
	echo.

if not exist c:\copytest md c:\copytest

rem setzt die Zeit vom Anfang und vom Ende des Kopiervorgangs. Für Stunde wird eine extra Variable benötigt wegen 9:15 / 09:15 
rem beinhaltet nun 2 unterschiedliche Varianten für 9:15 / 09:15. Erste Varitante wird unter USB ausgeführt und die zweite Variante unter HDD
set timeusbstart=%time%
	echo Start copy from USB to HDD - %timeusbstart%
	
copy %xxx% c:\copytest

set timeusbend=%time%
	echo Copy from USB to HDD successful - %timeusbend%

rem Zeit wird in einzelne Blöcke aufgeteilt

set "timeusbstart=%timeusbstart: =0%"  

if %timeusbstart:~0,1%==0 set usbstarthour=%timeusbstart:~1,1%
if not %timeusbstart:~0,1%==0 set usbstarthour=%timeusbstart:~0,2%

if %timeusbstart:~3,1%==0 set usbstartmin=%timeusbstart:~4,1%
if not %timeusbstart:~3,1%==0 set usbstartmin=%timeusbstart:~3,2%
if %timeusbstart:~6,1%==0 set usbstartsec=%timeusbstart:~7,1%
if not %timeusbstart:~6,1%==0 set usbstartsec=%timeusbstart:~6,2%
if %timeusbstart:~9,1%==0 set usbstarthsec=%timeusbstart:~10,1%
if not %timeusbstart:~9,1%==0 set usbstarthsec=%timeusbstart:~9,2%

if %timeusbstart:~0,1%==0 set usbendhour=%timeusbstart:~1,1%
if not %timeusbstart:~0,1%==0 set usbendhour=%timeusbstart:~0,2%

if %timeusbend:~3,1%==0 set usbendmin=%timeusbend:~4,1%
if not %timeusbend:~3,1%==0 set usbendmin=%timeusbend:~3,2%
if %timeusbend:~6,1%==0 set usbendsec=%timeusbend:~7,1%
if not %timeusbend:~6,1%==0 set usbendsec=%timeusbend:~6,2%
if %timeusbend:~9,1%==0 set usbendhsec=%timeusbend:~10,1%
if not %timeusbend:~9,1%==0 set usbendhsec=%timeusbend:~9,2%

rem startet den Test neu falls ein Stundensprung besteht
if not %usbstarthour%==%usbendhour% echo Test muss neu gestartet werden
if not %usbstarthour%==%usbendhour% echo Test muss wegen Stundensprung neu gestartet werden >>%log%
if not %usbstarthour%==%usbendhour% goto start
::	echo -- %usbcopy%

goto usbstart

:usbstart
rem hier wird die dauer jedes einzelnen Kopiervorgangs berechnet
set /a usbsec = (%usbendmin%*60+%usbendsec%)-(%usbstartmin%*60+%usbstartsec%)
::	echo (%usbendmin%*60+%usbendsec%)-(%usbstartmin%*60+%usbstartsec%)=%usbsec%
set /a usbhsec = %usbendhsec%-%usbstarthsec%
::	echo %usbendhsec%-%usbstarthsec%=%usbhsec%
set /a usbtime = %usbsec%*100+%usbhsec%
::	echo %usbsec%*100+%usbhsec%=%usbtime%

goto usbstep

:usbstep
rem Vorbereitung neuer Variablen zur durchschnittlichen Berechnung der Zeit
if /I %usbcopy%==0 set usb0=%usbtime%
if /I %usbcopy%==1 set usb1=%usbtime%
if /I %usbcopy%==2 set usb2=%usbtime%
if /I %usbcopy%==3 set usb3=%usbtime%
if /I %usbcopy%==4 set usb4=%usbtime%
if /I %usbcopy%==5 set usb5=%usbtime%
if /I %usbcopy%==6 set usb6=%usbtime%
if /I %usbcopy%==7 set usb7=%usbtime%
if /I %usbcopy%==8 set usb8=%usbtime%
if /I %usbcopy%==9 set usb9=%usbtime%

if /I %usbcopy%==9 goto usbcalc
set /a usbcopy = %usbcopy%+1

goto usbcopy

:usbcalc
rem hier wird die durchschnittliche Zeit berechnet von 10 Versuchen + 1000000 dient zusätzliche Stellen für weitere Berechnungen
	echo.
set /a usbtime10 = %usb0%+%usb1%+%usb2%+%usb3%+%usb4%+%usb5%+%usb6%+%usb7%+%usb8%+%usb9%
	echo usbtime10 %usb0%+%usb1%+%usb2%+%usb3%+%usb4%+%usb5%+%usb6%+%usb7%+%usb8%+%usb9%=%usbtime10%
	echo.
set /a usbtime = (%usbtime10%/10)+1000000
	echo. >>%log%
	echo Average Time to Copy %xxx% from USB to HDD: %usbtime:~3,2%,%usbtime:~5,2% seconds >>%log%
	echo. >>%log%
	
	echo Start copy File from HDD to HDD >>%log%
goto hddcopy

:hddcopy
set /a count=%hddcopy%+1
	echo.
	echo ###########################################
	echo      File copy in process! count: %count%/10
	echo ###########################################
	echo.

if not exist c:\copytest\hdd_to_hdd md c:\copytest\hdd_to_hdd

set timehddstart=%time%
set timehddhours=time /T
	echo Start copy from HDD to HDD - %timehddstart%

copy c:\copytest\%xxx% c:\copytest\hdd_to_hdd\%xxx%

set timehddend=%time%
set timehddhoure=time /T
	echo Copy from HDD to HDD successful - %timehddend%

if %timehddhours:~0,1%==0 set hddstarthour=%timehddhours:~1,1%
if not %timehddhours:~0,1%==0 set hddstarthour=%timehddhours:~0,2%

if %timehddstart:~3,1%==0 set hddstartmin=%timehddstart:~4,1%
if not %timehddstart:~3,1%==0 set hddstartmin=%timehddstart:~3,2%
if %timehddstart:~6,1%==0 set hddstartsec=%timehddstart:~7,1%
if not %timehddstart:~6,1%==0 set hddstartsec=%timehddstart:~6,2%
if %timehddstart:~9,1%==0 set hddstarthsec=%timehddstart:~10,1%
if not %timehddstart:~9,1%==0 set hddstarthsec=%timehddstart:~9,2%

if %timehddhoure:~0,1%==0 set hddendhour=%timehddhoure:~1,1%
if not %timehddhoure:~0,1%==0 set hddendhour=%timehddhoure:~0,2%

if %timehddend:~3,1%==0 set hddendmin=%timehddend:~4,1%
if not %timehddend:~3,1%==0 set hddendmin=%timehddend:~3,2%
if %timehddend:~6,1%==0 set hddendsec=%timehddend:~7,1%
if not %timehddend:~6,1%==0 set hddendsec=%timehddend:~6,2%
if %timehddend:~9,1%==0 set hddendhsec=%timehddend:~10,1%
if not %timehddend:~9,1%==0 set hddendhsec=%timehddend:~9,2%

if not %usbstarthour%==%usbendhour% echo Test muss neu gestartet werden
if not %usbstarthour%==%usbendhour% echo Test muss wegen Stundensprung neu gestartet werden >>%log%
if not %hddstarthour%==%hddendhour% goto start
::	echo -- %hddcopy%

goto hddstart

:hddstart
	echo.
set /a hddsec = (%hddendmin%*60+%hddendsec%)-(%hddstartmin%*60+%hddstartsec%)
::	echo (%hddendmin%*60+%hddendsec%)-(%hddstartmin%*60+%hddstartsec%)=%hddsec%
set /a hddhsec = %hddendhsec%-%hddstarthsec%
::	echo %hddendhsec%-%hddstarthsec%=%hddhsec%
set /a hddtime = %hddsec%*100+%hddhsec%
::	echo %hddsec%*100+%hddhsec%=%hddtime%

goto hddstep

:hddstep
if /I %hddcopy%==0 set hdd0=%hddtime%
if /I %hddcopy%==1 set hdd1=%hddtime%
if /I %hddcopy%==2 set hdd2=%hddtime%
if /I %hddcopy%==3 set hdd3=%hddtime%
if /I %hddcopy%==4 set hdd4=%hddtime%
if /I %hddcopy%==5 set hdd5=%hddtime%
if /I %hddcopy%==6 set hdd6=%hddtime%
if /I %hddcopy%==7 set hdd7=%hddtime%
if /I %hddcopy%==8 set hdd8=%hddtime%
if /I %hddcopy%==9 set hdd9=%hddtime%
if /I %hddcopy%==9 goto hddcalc

set /a hddcopy = %hddcopy%+1
goto hddcopy

:hddcalc
	echo.
set /a hddtime10 = %hdd0%+%hdd1%+%hdd2%+%hdd3%+%hdd4%+%hdd5%+%hdd6%+%hdd7%+%hdd8%+%hdd9%
	echo hddtime10 %hdd0%+%hdd1%+%hdd2%+%hdd3%+%hdd4%+%hdd5%+%hdd6%+%hdd7%+%hdd8%+%hdd9%=%hddtime10%
	echo.
set /a hddtime = (%hddtime10%/10)+1000000
	echo. >>%log%
	echo Average Time to Copy %xxx% from hdd to HDD: %hddtime:~3,2%,%hddtime:~5,2% seconds >>%log%
	echo. >>%log%
goto ready

:ready
rem das Ergebnis von USB/HDD Kopiervorgang
set /a size = %groesse%/1024/1024
	echo Tested with %xxx% Size: %size% MB (%groesse% Bytes)
	echo.

set /a usbmbpersec1 = %groesse%/(%usbtime%-1000000)
set /a usbmbpersec2 = %usbmbpersec1%
set usb=%usbtime:~3,2%,%usbtime:~5,2%
	echo Time for copy from USB to HDD %usb% seconds ~ %usbmbpersec2% Bytes/s
		echo Time for copy from USB to HDD %usb% seconds ~ %usbmbpersec2% Bytes/s >>%log%


set /a hddmbpersec1 = %groesse%/(%hddtime%-1000000)
set /a hddmbpersec2 = %hddmbpersec1%
set hdd=%hddtime:~3,2%,%hddtime:~5,2%
	echo Time for copy from HDD to HDD %hdd% seconds ~ %hddmbpersec2% Bytes/s
	echo Time for copy from HDD to HDD %hdd% seconds ~ %hddmbpersec2% Bytes/s >>%log%
	
goto exit

:exit
	echo Test is finished >>%log%
	echo -- del files

del c:\copytest\%log%
del c:\copytest\%xxx%
del c:\copytest\hdd_to_hdd\%xxx%
pause
exit

:fehler
	echo Die Datei %xxx% wurde nicht gefunden.
pause

goto exit

Danke nochmal
LG
Zendara