flat assembler
Message board for the users of flat assembler.

Index > DOS > Search and timing batch file

Author
Thread Post new topic Reply to topic
Fixit



Joined: 22 Nov 2012
Posts: 161
Fixit
I thought this might be interesting or of some help.

Andy

I figured this belonged in the Dos category.

Code:

 It took around 4.5 seconds to find 2 identical search.bat files in different directories using s*.bat as the search pattern.

I would like to fix it to where it searches without the search pattern being hard coded into the batch file.

I recall using %1.

:: Search.bat Dave Benham, mousio, Magnum,skywalker,
::

cls
@echo off
echo.
echo Timer has started.
echo.
call :StartTimer
::
:: Add your script functionality here
::
@echo off
setlocal disableDelayedExpansion
set "searchRoot=."
set "fileMask=s*.bat"

set "prior=noMatch"
for /f "tokens=1,2 delims=?" %%A in (
'(for /r "%searchRoot%" %%F in ("%fileMask%"^) do @echo %%~zF:%%~nxF?%%~fF^)^|sort'
) do (
set "current=%%A"
setlocal enableDelayedExpansion
if !prior! equ !current! (
if defined priorFile (
echo(
echo !priorFile!
)
endlocal
echo %%B
set "priorFile="
) else (
endlocal
set "prior=%%A"
set "priorFile=%%B"
)
)

call :StopTimer
call :DisplayTimerResult
pause
goto :EOF

:StartTimer
:: Store start time
set StartTIME=%TIME%
for /f "usebackq tokens=1-4 delims=:., " %%f in (`echo %StartTIME: =0%`) do set /a Start100S=1%%f*360000+1%%g*6000+1%%h*100+1%%i-36610100
goto :EOF

:StopTimer
:: Get the end time
set StopTIME=%TIME%
for /f "usebackq tokens=1-4 delims=:., " %%f in (`echo %StopTIME: =0%`) do set /a Stop100S=1%%f*360000+1%%g*6000+1%%h*100+1%%i-36610100
:: Test midnight rollover. If so, add 1 day=8640000 1/100ths secs
if %Stop100S% LSS %Start100S% set /a Stop100S+=8640000
set /a TookTime=%Stop100S%-%Start100S%
set TookTimePadded=0%TookTime%
goto :EOF

:DisplayTimerResult
:: Show timer start/stop/delta
echo Started: %StartTime%
echo Stopped: %StopTime%
echo Elapsed: %TookTime:~0,-2%.%TookTimePadded:~-2% seconds
goto :EOF

    
Post 14 Jan 2013, 07:10
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Fixit,

Is it any better than regular dir /s /b «filemask»?
Post 17 Jan 2013, 15:04
View user's profile Send private message Reply with quote
Fixit



Joined: 22 Nov 2012
Posts: 161
Fixit
It looks for identical files based on their file size.

I am working on making it to where you don't have to hard code the search criteria in the bat file.

Andy
Post 17 Jan 2013, 19:54
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Fixit,

If I got it right, your script searches for duplicate files? There are some intricacies in that: modern file systems have features like hard/symlinks, reparse points and such. For proper duplicates' identification cmd scripts seem to be underpowered.

Shell script can access its arguments with %1...%9. There is SS64 site with comprehensive reference for cmd scripting.
Post 18 Jan 2013, 13:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.