Jump to content

How can I determine the number of fragments in a file?


Recommended Posts

..but that has to do with the file system. As far as AutoIt knows, it requests a "file" and the OS reads it to it.

Edit: more over. If is an SSD or an iSCSI or HDD or .... . You can not defragment the file even if read and rewritten, as the file system is the one that handles that.

Edited by argumentum
expand

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Just a code snipped to show what i want:

Local $File = "C:\Windows\System32\Tasks\Microsoft\Windows\Defrag\ScheduledDefrag"
MsgBox(64+262144, Default, "the Fragmentscount of "&$File& " is "&_GetFragmentsCount($File),0)

Func _GetFragmentsCount($File)
    Local $Fragmentscount=0

;~  please insert the magic code here

    Return $Fragmentscount
EndFunc

 

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

I think you can use Contig from M$ with the a and v command line options. You'll need to parse the output, of course. https://docs.microsoft.com/en-us/sysinternals/downloads/contig (Link to documentation, not direct download)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

  • 2 weeks later...

Thanks to @seadoggie01 :thumbsup:

Based on his advice, I could build a solution:

#include <String.au3>

$File = "C:\Windows\System32\LogFiles\WMI\Wifi.etl"

$Pgm = @MyDocumentsDir & "\Data\Software\SysinternalsSuite\Contig.exe"
If Not FileExists($Pgm) Then MsgBox(16 + 262144, Default, "File " & $Pgm & " not found." & @LF & @LF & "Install it from here: https://live.sysinternals.com/Contig.exe", 0)

MsgBox(64 + 262144, Default, "The fragmentscount of " & @LF & @LF & $File & @LF & @LF & "is " & _GetFragmentsCount($File), 0)

Func _GetFragmentsCount($File)
    If Not FileExists($File) Then Return MsgBox(64+262144, Default, "File not found:"&@lf&@lf&$File,9)*0 + SetError(1, 0, 0)
    $iPID = Run(@ComSpec & " /c " & $Pgm & " -a -nobanner " & $File, "", default, 8)
    ProcessWaitClose($iPID)
    Local $sOutput = StdoutRead($iPID)
    ConsoleWrite($sOutput & @CRLF)
    $aFound = _StringBetween($sOutput, "in ", " Fragments")
    If @error Then Return SetError(0, 0, 1)
    Return $aFound[0]
EndFunc   ;==>_GetFragmentsCount

 

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...