Windows 10: defrag script for sysinternal contig

Discus and support defrag script for sysinternal contig in Windows 10 Performance & Maintenance to solve the problem; 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... Discussion in 'Windows 10 Performance & Maintenance' started by einstein1969, Jul 12, 2021.

  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. Code: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: By :: :: Ver 0.0.2 12/07/2021 :: :: You need download sysinternal contig (32bit) and copy in "windows\system32" folder :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: @Echo off setlocal enabledelayedexpansion set "Disk=N" rem italian set "string1=Dimensioni allocate" chcp 1252 echo Analyze the files. set f=0 for /f "tokens=*" %%F in ('contig -a -s "!Disk!:\*.*" ^| find "fragments"') 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 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" %%d in ('fsutil file layout "!fn!" ^| find "!string1!"') do if not defined dim set "dim=%%d" set "dim=!dim:.=!" ) else set "dim=0" echo [!f!] [type=!t!] [File_name=!fn!] [Frags=!fr!] [Dim=!dim!] ) pause goto :eof :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: EDIT: update script to version 0.0.2, fixed an error on retrive allocate dimension of file

    :)
     
    einstein1969, Jul 12, 2021
    #1

  2. Apparent bug in SysInternals Contig v1.8

    I can't find a SysInternals forum online. If this is not the right place to post this, please direct me elsewhere.

    There is an apparent bug in Contig v1.8. In some cases, "contig -s -v <filespec>" will not use the last block of free space on a volume. In other cases, it will. I've seen both behaviors on the same machine, but I can't explain when it happens and when
    it doesn't. I've been unable to defrag a file even though there is a huge amount of free space at the end of the volume.

    In this case, there was no other I/O in process to the volume (not the system volume) that could explain another task reserving the extent.

    Case 1 - "contig -s -v" does not use the last block of free space on the volume. Volume is FAT-32.

    D:\contig64 -f -v

     

    Contig v1.8 - Contig

    Copyright (C) 2001-2016 Mark Russinovich

    Sysinternals

     

    Starting Cluster: Free Cluster Count

    Scanning disk...

    1269630: 2

    1270596: 1

    1271187: 4

    1271192: 5

    1271198: 1

    1273467: 5

    1273537: 9

    1283856: 19

    1284167: 14

    1284371: 14

    1284601: 29

    1311252: 17

    1368792: 53

    1405668: 80

    1406822: 27

    1415456: 79

    1415537: 67

    1415605: 17

    1415623: 23

    1415647: 4

    1415652: 2

    1415655: 7

    1415663: 19

    1415683: 11

    1415695: 9

    1415705: 42

    1415748: 3

    1451459: 215

    1452663: 105

    1454364: 33

    1454398: 239

    1455645: 10

    1710779: 19

    1710799: 959

    1711759: 2

    1834751: 257

    1843330: 37

    1912139: 867

    1914620: 416

    1916714: 165

    1923375: 32

    1924811: 770

    1928388: 933

    1931423: 350

    1931938: 631

    1934713: 1277

    1936897: 467

    1937468: 323

    1939613: 152

    1944574: 434

    1945009: 300

    1945623: 682

    1947779: 770

    1954522: 738

    1955837: 1536

    Summary:

    Free cluster space : 0 bytes

    Free space fragments : 55 frags

    Largest free space block : 0 bytes

    Note the existence of a block of 1536 sectors of free space at the end of the volume.

    D:\contig -s -v *62b6*

     

    Contig v1.8 - Contig

    Copyright (C) 2001-2016 Mark Russinovich

    Sysinternals

     

    ------------------------

    Processing D:\62b6f34b4f139ff866d6151e71fe07b0-1.mp4:

    Scanning file...

    Scanning disk...

    File is 5811 physical clusters in length.

    File is in 8 fragments.

     

    Moving 1277 clusters at file offset cluster 0 to disk cluster 1934713

    Moving 959 clusters at file offset cluster 1277 to disk cluster 1710799

    Moving 933 clusters at file offset cluster 2236 to disk cluster 1928388

    Moving 867 clusters at file offset cluster 3169 to disk cluster 1912139

    Moving 770 clusters at file offset cluster 4036 to disk cluster 1924811

    Moving 770 clusters at file offset cluster 4806 to disk cluster 1947779

    Moving 235 clusters at file offset cluster 5576 to disk cluster 1954522

    File size: 95199118 bytes

    Fragments before: 8

    Fragments after : 7

    ------------------------

    Summary:

    Number of files processed: 1

    Number of files defragmented: 1

    Number unsuccessfully procesed: 0

    Average fragmentation before: 8 frags/file

    Average fragmentation after : 7 frags/file

     

    The block of 1536 clusters at the end of the volume was not used in defragging the file.

    Note also that "processed" is misspelled in the summary.

    Case 2 - "contig -s -v" does use the last block of free space on the volume. Volume is the same FAT-32 volume.

     

    D:\contig64 -f -v

     

    Contig v1.8 - Contig

    Copyright (C) 2001-2016 Mark Russinovich

    Sysinternals

     

    Starting Cluster: Free Cluster Count

    Scanning disk...

    1269630: 2

    1270596: 1

    1271187: 4

    1271192: 5

    1271198: 1

    1273467: 5

    1273537: 9

    1283856: 19

    1284167: 14

    1284371: 14

    1284601: 29

    1311252: 17

    1368792: 53

    1405668: 80

    1406822: 27

    1415456: 79

    1415537: 67

    1415605: 17

    1415623: 23

    1415647: 4

    1415652: 2

    1415655: 7

    1415663: 19

    1415683: 11

    1415695: 9

    1415705: 42

    1415748: 3

    1451459: 215

    1452663: 105

    1454364: 33

    1454398: 239

    1455645: 10

    1710779: 19

    1710799: 959

    1711759: 2

    1834751: 257

    1835009: 1773

    1841342: 2025

    1895478: 3312

    1909775: 3770

    Summary:

    Free cluster space : 0 bytes

    Free space fragments : 40 frags

    Largest free space block : 0 bytes

    At this time, the last block of free space is 3770 clusters.

     

    D:\contig -s -v *dd75*

     

    Contig v1.8 - Contig

    Copyright (C) 2001-2016 Mark Russinovich

    Sysinternals

     

    ------------------------

    Processing D:\dd75d0cb1101a8d50467442d0b32faec-1.mp4:

    Scanning file...

    Scanning disk...

    File is 5631 physical clusters in length.

    File is in 11 fragments.

     

    Moving 3770 clusters at file offset cluster 0 to disk cluster 1909775

    Moving 1861 clusters at file offset cluster 3770 to disk cluster 1895478

    File size: 92256416 bytes

    Fragments before: 11

    Fragments after : 2

    ------------------------

    Processing D:\7af7bc409ab726512722ffbcf99dd755.mp4:

    Scanning file...

    D:\7af7bc409ab726512722ffbcf99dd755.mp4 is already in 1 fragment.

    ------------------------

    Summary:

    Number of files processed: 2

    Number of files defragmented: 1

    Number unsuccessfully procesed: 1

    Average fragmentation before: 6 frags/file

    Average fragmentation after : 1.5 frags/file

     

    In this case, the free space extent at the end of the volume was used when defragmenting.

    So the behavior appears to be inconsistent. Note that, in both cases, the largest extent of free space was at the end of the volume.

     

     

     
     
    PatB in California, Jul 12, 2021
    #2
  3. Windows 10 won't defrag

    It looks like there's some files and folders it doesn't want to touch. In cases like this on a traditional hard disk, I recommend using

    Sysinternals' Contig
    utility which ensures that files are contiguous (all one piece, not fragmented).

    • Navigate to the above link and download the ZIP file and extract it to a location of your choice.
    • Open an Administrator Command Prompt window like before, and navigate to where the folder is located.
    • Run contig.exe /s /v C:\*.* (You may be prompted to accept the EULA first).
    • You'll see a lot of stuff scroll across the screen indicating file name, fragments before, and fragments after, and finally a summary at the end.
    Copy and paste the summary at the end for reference and check the disk defragmenter again after running contig.exe, the amount of fragmented space should be lower.
     
    KristanKenney, Jul 12, 2021
    #3
  4. mrm3601 Win User

    defrag script for sysinternal contig

    How to Remove Sysinternals Live?


    I mistakenly downloaded and installed Sysinternals Live instead of only Autoruns.

    I've looked through my list of installed programs but I don't see SysInternals Live.

    Can anyone suggest a method by which I can remove SystInternals Live from my PC?

    Thank you.
     
    mrm3601, Jul 12, 2021
    #4
Thema:

defrag script for sysinternal contig

Loading...
  1. defrag script for sysinternal contig - Similar Threads - defrag script sysinternal

  2. Defrag . . .

    in Windows 10 Software and Apps
    Defrag . . .: I used the defrag, built into Windows 10 & 11It did, a good job! But, I was wondering?Is is there a third party, version of defrag.That would, defragment. A Windows 10, & Windows 11.Dual partition hard drive? Hopefully it would go, a little further?Any suggestions, would be...
  3. Windows defrag doesnt defrag

    in Windows 10 BSOD Crashes and Debugging
    Windows defrag doesnt defrag: Windows 10 Pro defrag utility shows my HDD as needing "optimization" saying the defrag level is at 13%. I start the "optimization" defrag process and it goes through 5 passes of defragging,consolidating etc then stops and still says its defrag level is at 13% - in other...
  4. defrag

    in Windows 10 BSOD Crashes and Debugging
    defrag: Does defrag remove files that I have deleted ? https://answers.microsoft.com/en-us/windows/forum/all/defrag/dd96aa2f-354e-4229-9ebc-230e5ead0cd0
  5. Apparent bug in SysInternals Contig v1.8

    in Windows 10 BSOD Crashes and Debugging
    Apparent bug in SysInternals Contig v1.8: I can't find a SysInternals forum online. If this is not the right place to post this, please direct me elsewhere. There is an apparent bug in Contig v1.8. In some cases, "contig -s -v <filespec>" will not use the last block of free space on a volume. In other cases, it...
  6. To defrag or not to defrag? (non-SSD)

    in Windows 10 Performance & Maintenance
    To defrag or not to defrag? (non-SSD): My secondary drive in my system is a 2TB standard hard drive. Windows 10 defrag (both UI and the command line) tells me that I do not need to defrag the disk, as it is "0% fragmented" but upon delving a little further (adding the /V switch) I notice that it doesn't include...
  7. Defrag

    in Windows 10 BSOD Crashes and Debugging
    Defrag: How do I defrag my computer in Windows 10? The instructions say to choose the search bar on the taskbar but I don't have a search bar. https://answers.microsoft.com/en-us/windows/forum/windows_10-performance/defrag/9f747c8d-5d36-4c2c-b933-227488d99d2e
  8. Windows Sysinternals Utilities

    in Windows 10 Software and Apps
    Windows Sysinternals Utilities: Microsoft has released new versions of: Autoruns Autoruns 13.51 and Process Explorer Version 16.1 36498
  9. How to Remove Sysinternals Live?

    in Windows 10 Software and Apps
    How to Remove Sysinternals Live?: I mistakenly downloaded and installed Sysinternals Live instead of only Autoruns. I've looked through my list of installed programs but I don't see SysInternals Live. Can anyone suggest a method by which I can remove SystInternals Live from my PC? Thank you. 52267
  10. Defrag

    in Windows 10 Performance & Maintenance
    Defrag: Having set win 10 defrag to work on a daily bases - it's not working. Gone three days now and no optimization. Anyone come across this? or know of a fix. Pete.*Sad 30186