New
#1
defrag script for sysinternal contig
Hi,
I'm writing a batch for defrag file with the sysinternal contig.
I need a hand to develop and test it better. For now it performs only the analysis and is developed for the "Italian" language but I would like to make it more flexible.
EDIT: update script to version 0.0.2, fixed an error on retrive allocate dimension of fileCode::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Edefrag - By Einstein1969 :: :: Ver 0.0.3 13/07/2021 :: :: You need download sysinternal contig (32bit) and copy in "windows\system32" folder :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: @echo off (Fsutil Dirty Query %SystemDrive%>Nul)||(PowerShell start """%~fn0""" -verb RunAs & Exit /B) setlocal EnableDelayedExpansion & if "%1" == "wait" goto :wait set "Disk=C" rem set/p "Disk=Insert Disk Letter and press Enter (default=!Disk!). Es. 'C' >" set "minfrags=4" rem italian set "string1=Dimensioni allocate" chcp 1252 echo Searching for fragmented files. cd %TMP% ( del stop.tmp 2>nul contig -a -s "%Disk%:\*.*" | find "fragments" >Edefrag.log type nul: >stop.tmp ) | %0 wait echo( echo Analyze the files with minimum !minfrags! frags. set f=0 for /f "tokens=*" %%F in ('more Edefrag.log') do ( call set "s=%%F" set "s=!s:*...=!" set "s=!s:~0,-10!" for %%A in ("!s: =\!") do set "fr=%%~nA" if not defined fr echo [!s!] Error in frags number. & pause & goto :eof if !fr! geq !minfrags! ( set "$=!fr!fedcba9876543210" set/a l=0x!$:~16,1!+1, f+=1 for %%A in ("!l!") do set "fn=!s:~,-%%~A!" set "fn=!fn:~,-7!" if not exist "!fn!" echo [!fn!] Error, file not found. & pause & goto :eof for %%A in ("!fn!") do set "t=%%~aA" if not defined t echo [!fn!] [!fr!] Error in attributes. & pause & goto :eof if "!t:~0,1!"=="d" (set "t=d") else set "t=f" set "dim=" if "!t!"=="f" ( for /f "tokens=4*" %%c in ('fsutil file layout "!fn!" ^| find "!string1!"') do if not defined dim set "dim=%%d" rem set "dim=!dim:.=!" ) else set "dim=NA" set "f_= !f!" echo !f_:~-4! [!t!] !fr! frags [!fn!] Dim=!dim! ) ) pause goto :eof :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :wait rem echo %2 is running... for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a" set "s=|/-\" set LN=0 for /L %%N in (0) do ( ping -n 2 127.0.0.1 >nul set /a "N=(N+1) %% 5" if !N! equ 0 ( if !LN! equ 0 ( for /f %%L in ('FIND /V /C "" ^< Edefrag.log') do set /A LN=%%L, LLN=%%L-1 ) else ( for /f %%L in ('More Edefrag.log +!LN! ^| FIND /V /C ""') do set /A LN+=%%L, LLN=LN-1 ) set "v=" if !LN! gtr 0 for /f "tokens=*" %%S in ('more Edefrag.log +!LLN!') do call set "v=%%S" if defined v set "v=!v:*...=!" & set /P "=_!CR! Found !LN! elements: !v:~0,60!... !CR!" < nul ) set /P "=_!CR![!s:~0,1!]" < nul set "s=!s:~-3!!s:~0,1!" if exist stop.tmp echo(&exit ) goto :eof :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
EDIT: update script to version 0.0.3, fixed some error and make faster.
Last edited by einstein1969; 13 Jul 2021 at 15:28. Reason: update script to version 0.0.3