Code: Select all

```
@ECHO OFF
:: define a newline with line continuation
(SET \n=^^^
%= This defines an escaped Line Feed - DO NOT ALTER =%
)
:: echo text to the console without CR/LF
SET "eko=<NUL SET/P="
:: print everything but % without DelayedExpansion
SET "prt=@FOR /F %%^" in ("""")DO @ECHO(%%~""
%PRT%Print &,|,<,>, or ^ without escaping! Still gotta double %% though...
:: pause with custom (or no) message
SET "poz=@FOR %%# IN (1 2)DO @IF %%#==2 (PAUSE>NUL&ECHO.)ELSE <NUL SET/P="
%POZ%Your message and pause the script until user hits a key...
:: recursively remove all empty folders from a directory tree
SET nullDir=FOR %%# IN (1 2)DO IF %%#==2 (%\n%
FOR /F "tokens=*" %%: IN ('DIR /AD-S/B/S !##! 2^^^>NUL ^^^|SORT/R')DO RD "%%:"^>NUL 2^>^&1%\n%
ENDLOCAL%\n%
)ELSE SETLOCAL EnableDelayedExpansion^&SET ##=%= \Path\to\Folder =%
:: %timeSince% %TIME% [%DATE% [part whole]]
:: input - hh:mm:ss.cc [Day MM/DD/YYYY [integer integer]]
:: output - [Wwks, ][Dday, ][Hhrs, ][Mmin, ]S.Csec
:: returns time lapsed from %TIME% [%DATE%] to present in TS_ or if given
:: part/whole will return estimate of time remaining to completion in TR_.
:: raw time and day info for given(1) and current(2) are also available.
:: TM1,TM2=# of centiseconds since last midnight.
:: DY1,DY2=# of days since noon on January 1, 4713 BCE (Julian calendar).
:: usage:
:: SET "startTime=%TIME%" or "startTime=%TIME% %DATE%" before event then:
:: %timeSince% %startTime% - for current elapsed time.
:: %timeSince% %startTime% %partCnt% %wholeCnt% - to estimate by count.
:: %timeSince% %startTime% %partKb% %wholeKb% - to estimate by size.
::
SET timeSince=FOR %%# IN (1 2)DO IF %%#==2 (%= 'v0.2 2018/08/06 =%%\n%
%= =%SET res=^& SET var=TS_%= 'res=result,var=TS_=time elapsed since start time =%%\n%
%= =%SET/A p=t=t1=tm1=t2=tm2=d=d1=dy1=d2=dy2=y=z=0%= p=counter for parameters,y==part,z=whole =%%\n%
%= t=t2-t1=target time,t1/t2=adjusted start/current time,tm1/tm2=raw start/current time (in centiseconds)=%%\n%
%= d=d2-d1=target day, d1/d2=adjusted start/current day, dy1/dy2=raw start/current day (Julian calendar)=%%\n%
%= =%IF "!inp:~1,1!"==":" SET inp=0!inp!%= 'add leading zero if needed =%%\n%
%= =%FOR %%@ IN ("!inp!" "!TIME: =0! !DATE!")DO (SET/A p+=1%= 'convert input and current time/day =%%\n%
%= =%FOR /F "tokens=1-10 delims=:./ " %%A IN ("%%~@")DO IF "%%D" NEQ "" (%= 'separate string,check for TIME =%%\n%
%= =%SET/A"tm!p!=t!p!=(((1%%A*60)+1%%B)*60+1%%C)*100+1%%D-36610100"%= 'convert time to centiseconds =%%\n%
%= =%IF "%%H" NEQ "" (SET/A mm=100%%F%%100,dd=100%%G%%100,yy=10000%%H%%10000%= 'check for DATE,extract MM,DD,YYYY =%%\n%
%= =%SET/A"dy!p!=d!p!=!dd!-32075+1461*(!yy!+4800+(!mm!-14)/12)/4+367*(!mm!-2-(!mm!-14)/12*12)/12-3*((!yy!+4900+(!mm!-14)/12)/100)/4")%\n%
%= =%IF "%%J" NEQ "" SET/A y=%%I,z=%%J))%= 'convert Gregorian to Julian,snag part/whole parameters if available =%%\n%
%= =%IF !t1! GEQ !t2! SET/A t2+=8640000,d2-=1%= 'if start>=current we've past midnight,convert 1day=8640000cs =%%\n%
%= =%IF !d1! EQU 0 SET d2=0%= 'if no start date clear current date =%%\n%
%= =%SET/A t=t2-t1,d=d2-d1%= 'target time/day =%%\n%
%= =%FOR %%A IN (1 2 3)DO IF !z! GTR 9999999 SET/A y/=10,z/=10%= 'reduce part/whole to 7 digits =%%\n%
%= =%IF !y! LSS 1 SET y=1%= 'and calculate time remaining from part/whole ratio =%%\n%
%= =%IF !z! NEQ 0 SET/A"t=(z-y)*100/y*((d*8640000+t)/100),d=t/8640000,t=t%%8640000"^& SET var=TR_%\n%
%= =%SET/A w=d/7,d=d%%7,h=t%%8640000/360000,m=t%%360000/6000,s=t%%6000/100,c=t%%100%\n%
%= =%IF !c! LEQ 9 SET c=0!c!%= 'reduce centiseconds to months,weeks,days,hours,minutes,seconds =%%\n%
%= =%IF !w! GTR 0 SET res=!w!wks, %= 'w=weeks =%%\n%
%= =%IF !d! GTR 0 SET res=!res!!d!day, %= 'd=days =%%\n%
%= =%IF !h! GTR 0 SET res=!res!!h!hrs, %= 'h=hours =%%\n%
%= =%IF !m! GTR 0 SET res=!res!!m!min, %= 'm=minutes =%%\n%
%= =%SET res=!var!=!res!!s!.!c!sec%= 's=seconds,c=centiseconds =%%\n%
%= =%SET res=!res!" "tm1=!tm1!" "tm2=!tm2!" "dy1=!dy1!" "dy2=!dy2!%= 'quote-separated queue of return variables =%%\n%
%= =%FOR /F "tokens=*" %%A IN (^""!res!"^")DO ENDLOCAL^& FOR %%B IN (%%A)DO SET %%B%= 'exit & cycle through return queue =%%\n%
)ELSE SETLOCAL EnableDelayedExpansion^& SET inp=
%timeSince% 21:05:32.00 Day 09/18/2017
%timeSince% 20:34:12.00 Day 08/06/2018 5 10 'ratio of 1/2 means remainingTime=elapsedTime
ECHO timeSince v0.1 created %TS_% ago.
ECHO timeSince v0.2 created %TR_% ago.
```

As always give a try if it suits your fancy, and please post if you encounter any issues.