lundi 8 janvier 2018

Batch check for whitespace

I want to name my batch logfile with the timestamp were it was created. But there is a problem if the time is < 10am. Then I get a whitespace and the filename will be corrupted. I tried to catch that via IF but somehow its not working and the cmd window is closing immediately:

set f_null=%time:~-11,1%
If /i %f_null% == " " (set zeitstempel_start=%DATE:~-4%%DATE:~-7,-5%%DATE:~-10,-8%0%time:~-10,1%%time:~-8,2%%time:~-5,2%) else
                      (set zeitstempel_start=%DATE:~-4%%DATE:~-7,-5%%DATE:~-10,-8%%time:~-11,2%%time:~-8,2%%time:~-5,2%)

set startzeit=Start: %date% %time:~-11,2%:%time:~-8,2%:%time:~-5,2%
set datei_name=%zeitstempel_start%
echo %startzeit% > %def_log_dir%\%datei_name%.log 

Any idea what the problem is?

Aucun commentaire:

Enregistrer un commentaire