windows - Batch for scanning dirs needs a possibility to skip defined dirs -
i have batch scans directory structure , gives out size of directorys defined should for.
e.g. directory '10xxx' contains subdirectorys '10001', '10002' , '10003'. lets batch should dir 'xyz' in subdirs. result .csv informations '10001\xyz' 100 bytes; '10002\xyz' 2000 bytes; '10003\xyz' 0 bytes.
the problem batch scans every directory every time runs, takes lot of time , resources.
my idea implement section code everytime batch starts scanning dir takes .txt (for example) , when dir name found in file batch skips dir. maybe not effective solution, take less time , resources scanning every dir every time. different ideas of course welcome.
unfortunately have not enough knowledge myself hope me.
code:
@echo off &setlocal set /p rootfolder=<enter_directory_path_here.txt set /p savefolder=<enter_save_directory_here.txt set "batpath=%~dp0" pushd "%rootfolder%" /d %%i in (*) ( set "foldername=%%~nxi" set "folder=%%i" >"%batpath%%%~nxi.csv" type nul /f "delims=" %%j in ('dir /ad /b "%%i\*"') ( set "subfolder=%%j" call :procfolder ) >"%batpath%%%~nxi.~csv" type nul /f "usebackq tokens=1* delims==" %%j in ("%savefolder%\patterns.txt") ( >>"%batpath%%%~nxi.~csv" findstr /b %%k "%batpath%%%~nxi.csv" if errorlevel 1 >>"%batpath%%%~nxi.~csv" echo "%%j";"not found" ) >nul move /y "%batpath%%%~nxi.~csv" "%batpath%%%~nxi.csv" ) popd call :cleaner exit /b :procfolder setlocal /f "tokens=3" %%i in ('dir /a /-c "%folder%\%subfolder%\"^|findstr /c:"datei(en)"') >>"%batpath%%foldername%.csv" echo "%subfolder%";%%i;"bytes" /f "delims=" %%i in ('dir /ad /b "%folder%\%subfolder%\"') ( set "subfolder=%subfolder%\%%i" call :procfolder ) endlocal exit /b
a sample of reading text file match
for /f "tokens=*" %%x in (n:\somedirectory\somefile.txt) if /i "%foldername%" equ "%%x" goto skipit rem normal stuff here :skipit if exclusion filename encapsulated in quotes, add usebackq option:
for /f "usebackq tokens=*" %%x in ("n:\some directory\some file.txt") if /i "%foldername%" equ "%%x" goto skipit rem normal stuff here :skipit
Comments
Post a Comment