Jump to content

Getting Size on Disk


SoulA
 Share

Recommended Posts

I'm having a lot of trouble and my searches of both the internet and the forums haven't really helped too much. It led me in some directions but not to the answer.

Basically, I want to get the "Size on Disk" value as opposed to just the "Size" value that you see when you right click on files or folders. It looks like DirGetSize and FileGetSize will give just the "Size" value.

Any help would be greatly appreciated.

Link to comment
Share on other sites

DriveSpaceTotal ( "path" )

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

not really what I'm looking for unless this is a clue to something I'm missing.

Search WinAPIEx.au3 and then use the Function _WinAPI_GetFileSizeOnDisk() or have a look here But I would recommend the initial suggestion :x

Edit: Varian beat me to it as I was posting and searching the forum, the example they have provided is the same code as _WinAPI_GetFileSizeOnDisk() so use that example for ease :P

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Edit: Varian beat me to it as I was posting and searching the forum, the example they have provided is the same code as _WinAPI_GetFileSizeOnDisk() so use that example for ease :x

Swissshhhh!!!! Edited by Varian
Link to comment
Share on other sites

It was a quick edit, but I saw the use of incorrect

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

This has been really helpful. Thank you very much for all of the suggestions. Just to add on to my problem I think what I'm dealing with are actually sparse files. So the "Size" will be something like 20GB's but they "SizeOnDisk" will actually only be 13GB's. So it all is a bit funky now and none of the cluster size to file size relationships work out.

Link to comment
Share on other sites

I can only think of moving the files onto another disk and back again, but this is probably stupid advice!

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

You need to "use the GetCompressedFileSize function to obtain the actual size allocated on disk for a sparse file".

http://msdn.microsoft.com/en-us/library/aa365276.aspx

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
Global $sFile = FileOpenDialog("Select a file:", @ScriptDir, "All (*.*)", 1)
If $sFile = "" Then Exit
Global $aRet = DllCall("Kernel32.dll", "dword", "GetCompressedFileSize", "str", $sFile, "dword", Chr(0))
MsgBox(64, "File Size On Disk (Bytes)", $aRet[0])
Awesome, thank you all.
Link to comment
Share on other sites

You need to "use the GetCompressedFileSize function to obtain the actual size allocated on disk for a sparse file".

http://msdn.microsoft.com/en-us/library/aa365276.aspx

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
Global $sFile = FileOpenDialog("Select a file:", @ScriptDir, "All (*.*)", 1)
If $sFile = "" Then Exit
Global $aRet = DllCall("Kernel32.dll", "dword", "GetCompressedFileSize", "str", $sFile, "dword", Chr(0))
MsgBox(64, "File Size On Disk (Bytes)", $aRet[0])
After testing this out and looking at the documentation this only works on files less than 4GB and I need to get the data for things larger than that. I'm not too familiar with how this works but it seems like lpFileSizeHigh needs to be something other than null.
Link to comment
Share on other sites

Yeah, I knew that when I posted the code, but I was hoping you were using small files. I'm not exactly sure how to use the function properly with larger files due to my lack of DllStruct knowledge.

I don't have any sparse files to test this so I don't know which value is the correct one, if any.

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
Global $sFile = FileOpenDialog("Select a file:", @ScriptDir, "All (*.*)", 1)
If $sFile = "" Then Exit
Global $tFileSizeHigh = DllStructCreate("dword")
Global $aRet = DllCall("Kernel32.dll", "dword", "GetCompressedFileSize", "str", $sFile, "dword", DllStructGetPtr($tFileSizeHigh))
MsgBox(64, "File Size On Disk (Bytes)", $aRet[0] & @CRLF & $aRet[2] & @CRLF & DllStructGetData($tFileSizeHigh, 1))

Here's another link for anyone else that might want to help.

http://winapi.freetechsecrets.com/win32/WIN32GetCompressedFileSize.htm

You should be able to use any file over 4GB's. It should return the uncompressed size if I'm reading things right.
Link to comment
Share on other sites

Nice Function Deathbringer, added to the Function Folder! :x Surprised that this isn't in WinAPIEx.au3

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Here's a working '_FileGetCompressedSize' function, plus a 'FileGetAttributes' function which is handy for determining if a file is compressed or a reparse point. (Use BitAnd(attrib,value) to test).

#include <WinAPI.au3>
; ===================================================================================================================
; Func _FileGetCompressedSize($sFile)
;
; Function to get 'Compressed' File Size of the given file, which means one of two things:
;   1.) If the file is compressed OR a 'sparse' file, the return is the size in bytes on disk
;   2.) If the file is a normal file, the return is the *file* size, NOT the size in bytes on disk
;   To avoid confusion, get the file attributes, test for sparse/compressed type, then call the appropriate function
;
; Author: Ascend4nt
; ===================================================================================================================

Func _FileGetCompressedSize($sFile)
    If Not IsString($sFile) Or $sFile='' Then Return SetError(1,0,-1)
    Local $aRet=DllCall('kernel32.dll','dword','GetCompressedFileSizeW','wstr',$sFile,'dword*',0)
    If @error Then Return SetError(2,0,-1)
#cs
    ; -------------------------------------------------------------------------------------------------------------------
    ; Per MSDN, a return of 0 in FileSizeHigh AND a return of INVALID_FILE_SIZE (0xFFFFFFFF) in FileSizeLow means failure
    ;   The size of a file on disk will NEVER be INVALID_FILE_SIZE, which is an odd # (4,294,967,295 bytes to be exact),
    ;   however on regular (uncompressed, non-sparse file) files, this IS possible.
    ;   This requires a third check using GetLastError API call. Non-zero means the call failed.
    ; -------------------------------------------------------------------------------------------------------------------
#ce
    ; Size is 'INVALID_FILE_SIZE' and GetLastError returns something other than 'NO_ERROR' (0)?
    If $aRet[2]=0 And $aRet[0]=0xFFFFFFFF And _WinAPI_GetLastError()<>0 Then Return SetError(3,0,-1)
    Local $stFileSize64=DllStructCreate("uint64"),$stFileSizePts=DllStructCreate("dword[2]",DllStructGetPtr($stFileSize64))
    DllStructSetData($stFileSizePts,1,$aRet[0],1)
    DllStructSetData($stFileSizePts,1,$aRet[2],2)
    Return DllStructGetData($stFileSize64,1)
EndFunc

; ===================================================================================================================
; Func _FileGetAttributes($sFile)
;
; Get File Attributes - fixes another half-baked AutoIt built-in function ( FileGetAttrib() )
;
; NOTE: To be TOTALLY accurate all the time, its best to use 'GetFileInformationByHandle' API to get File Attributes
;   (This requires opening the file using _WinAPI_CreateFile($sFile,2,2,6) and calling _WinAPI_CloseHandle() after)
;   This isn't usually a problem unless files are not updated (NTFS file system updates itself at 1-hour intervals),
;   or are being written to.
;   See <_FileMonitorAccessTime.au3> for an example of how the update works and how to workaround it.
;
; For Attributes returned, see 'File Attribute Constants (Windows)' @ MSDN:
;   http://msdn.microsoft.com/en-us/library/gg258117%28v=VS.85%29.aspx
;
; Some values not returned by FileGetAttrib():
;   FILE_ATTRIBUTE_SPARSE_FILE   = 512 (0x200)
;   FILE_ATTRIBUTE_REPARSE_POINT = 1024 (0x400)
; One that is returned, but since 'GetCompressedFileSize' should only be used for SPARSE & COMPRESSED files..
;   FILE_ATTRIBUTE_COMPRESSED   = 2048 (0x800)
;
;
; Author: Ascend4nt
; ===================================================================================================================

Func _FileGetAttributes($sFile)
    If Not IsString($sFile) Or $sFile='' Then Return SetError(1,0,0)
    Local $aRet=DllCall('kernel32.dll','int','GetFileAttributesW','wstr',$sFile)
    If @error Then Return SetError(2,0,-1)
    ; INVALID_FILE_ATTRIBUTES (-1)? API call failed
    If $aRet[0]=-1 Then Return SetError(3,0,-1)
    Return $aRet[0]
EndFunc

Symbolic Links are another issue.. there may be an undocumented function to determine if a file is one of these, but I choose to use a simple DOS 'Dir' command which checks for '<JUNCTION>' in the output.. then you can easily ignore the file size. You can also use 'Dir' with the '-L' attribute to skip symbolic links.

*edit: forgot to add <WinAPI.au3> include

Edited by Ascend4nt
Link to comment
Share on other sites

Here's a working '_FileGetCompressedSize' function, plus a 'FileGetAttributes' function which is handy for determining if a file is compressed or a reparse point. (Use BitAnd(attrib,value) to test).

Again a nice piece of code... that goes straight into SMF :x...

Symbolic Links are another issue.. there may be an undocumented function to determine if a file is one of these.

Can't this be derived from FindNextFile?

FindNextFile : "If the path points to a symbolic link, the WIN32_FIND_DATA buffer contains information about the symbolic link, not the target."

WIN32_FIND_DATA: "If the dwFileAttributes member includes the FILE_ATTRIBUTE_REPARSE_POINT attribute, this member specifies the reparse point tag."

IO_REPARSE_TAG_DFS

IO_REPARSE_TAG_DFSR

IO_REPARSE_TAG_HSM

IO_REPARSE_TAG_HSM2

IO_REPARSE_TAG_MOUNT_POINT

IO_REPARSE_TAG_SIS

IO_REPARSE_TAG_SYMLINK

Link to comment
Share on other sites

Nah, just tried it and it proved futile in detecting a symbolic link.

*edit: Actually, sorry about that - I'm confused with all the terminology now. I have a hard link in one folder that doesn't get detected, which I originally thought was a form of a Symbolic Link. But is it? MSDN is confusing on the matter.

What you describe above does work for Junctions, as I've just tested it on the @UserProfileDir on Win7 (a number of Junctions there). Now I have no clue about Symbolic Links.. I've got to figure out what that is and why MSDN says it differs from Junctions and Hard Links..

Edited by Ascend4nt
Link to comment
Share on other sites

Link to comment
Share on other sites

Here's a working '_FileGetCompressedSize' function, plus a 'FileGetAttributes' function which is handy for determining if a file is compressed or a reparse point. (Use BitAnd(attrib,value) to test).

#include <WinAPI.au3>
; ===================================================================================================================
; Func _FileGetCompressedSize($sFile)
;
; Function to get 'Compressed' File Size of the given file, which means one of two things:
;   1.) If the file is compressed OR a 'sparse' file, the return is the size in bytes on disk
;   2.) If the file is a normal file, the return is the *file* size, NOT the size in bytes on disk
;   To avoid confusion, get the file attributes, test for sparse/compressed type, then call the appropriate function
;
; Author: Ascend4nt
; ===================================================================================================================

Func _FileGetCompressedSize($sFile)
    If Not IsString($sFile) Or $sFile='' Then Return SetError(1,0,-1)
    Local $aRet=DllCall('kernel32.dll','dword','GetCompressedFileSizeW','wstr',$sFile,'dword*',0)
    If @error Then Return SetError(2,0,-1)
#cs
    ; -------------------------------------------------------------------------------------------------------------------
    ; Per MSDN, a return of 0 in FileSizeHigh AND a return of INVALID_FILE_SIZE (0xFFFFFFFF) in FileSizeLow means failure
    ;   The size of a file on disk will NEVER be INVALID_FILE_SIZE, which is an odd # (4,294,967,295 bytes to be exact),
    ;   however on regular (uncompressed, non-sparse file) files, this IS possible.
    ;   This requires a third check using GetLastError API call. Non-zero means the call failed.
    ; -------------------------------------------------------------------------------------------------------------------
#ce
    ; Size is 'INVALID_FILE_SIZE' and GetLastError returns something other than 'NO_ERROR' (0)?
    If $aRet[2]=0 And $aRet[0]=0xFFFFFFFF And _WinAPI_GetLastError()<>0 Then Return SetError(3,0,-1)
    Local $stFileSize64=DllStructCreate("uint64"),$stFileSizePts=DllStructCreate("dword[2]",DllStructGetPtr($stFileSize64))
    DllStructSetData($stFileSizePts,1,$aRet[0],1)
    DllStructSetData($stFileSizePts,1,$aRet[2],2)
    Return DllStructGetData($stFileSize64,1)
EndFunc

; ===================================================================================================================
; Func _FileGetAttributes($sFile)
;
; Get File Attributes - fixes another half-baked AutoIt built-in function ( FileGetAttrib() )
;
; NOTE: To be TOTALLY accurate all the time, its best to use 'GetFileInformationByHandle' API to get File Attributes
;   (This requires opening the file using _WinAPI_CreateFile($sFile,2,2,6) and calling _WinAPI_CloseHandle() after)
;   This isn't usually a problem unless files are not updated (NTFS file system updates itself at 1-hour intervals),
;   or are being written to.
;   See <_FileMonitorAccessTime.au3> for an example of how the update works and how to workaround it.
;
; For Attributes returned, see 'File Attribute Constants (Windows)' @ MSDN:
;   http://msdn.microsoft.com/en-us/library/gg258117%28v=VS.85%29.aspx
;
; Some values not returned by FileGetAttrib():
;   FILE_ATTRIBUTE_SPARSE_FILE   = 512 (0x200)
;   FILE_ATTRIBUTE_REPARSE_POINT = 1024 (0x400)
; One that is returned, but since 'GetCompressedFileSize' should only be used for SPARSE & COMPRESSED files..
;   FILE_ATTRIBUTE_COMPRESSED   = 2048 (0x800)
;
;
; Author: Ascend4nt
; ===================================================================================================================

Func _FileGetAttributes($sFile)
    If Not IsString($sFile) Or $sFile='' Then Return SetError(1,0,0)
    Local $aRet=DllCall('kernel32.dll','int','GetFileAttributesW','wstr',$sFile)
    If @error Then Return SetError(2,0,-1)
    ; INVALID_FILE_ATTRIBUTES (-1)? API call failed
    If $aRet[0]=-1 Then Return SetError(3,0,-1)
    Return $aRet[0]
EndFunc

Symbolic Links are another issue.. there may be an undocumented function to determine if a file is one of these, but I choose to use a simple DOS 'Dir' command which checks for '<JUNCTION>' in the output.. then you can easily ignore the file size. You can also use 'Dir' with the '-L' attribute to skip symbolic links.

*edit: forgot to add <WinAPI.au3> include

Everything I have tested with this shows it's working for at least what I'm doing. Thank you very much.
Link to comment
Share on other sites

I'm having a lot of trouble and my searches of both the internet and the forums haven't really helped too much. It led me in some directions but not to the answer.

Basically, I want to get the "Size on Disk" value as opposed to just the "Size" value that you see when you right click on files or folders. It looks like DirGetSize and FileGetSize will give just the "Size" value.

Any help would be greatly appreciated.

$DriveArray = DriveGetDrive("all")
If Not @error Then
    $DriveInfo = ""
    For $DriveCount = 1 to $DriveArray[0]
        $DriveInfo &= StringUpper($DriveArray[$DriveCount])
        $DriveInfo &= " -  File System = " & DriveGetFileSystem($DriveArray[$DriveCount])
        $DriveInfo &= ",  Label = " & DriveGetLabel($DriveArray[$DriveCount])
        $DriveInfo &= ",  Serial = " & DriveGetSerial($DriveArray[$DriveCount])
        $DriveInfo &= ",  Type = " &  DriveGetType($DriveArray[$DriveCount])
        $DriveInfo &= ",  Free Space = " & DriveSpaceFree($DriveArray[$DriveCount])
        $DriveInfo &= ",  Total Space = " & DriveSpaceTotal($DriveArray[$DriveCount])
        $DriveInfo &= ",  Status = " & DriveStatus($DriveArray[$DriveCount])
        $DriveInfo &= @CRLF
    Next
    MsgBox(4096,"Drive Info", $DriveInfo)
EndIf

give this a try it i think it is what your looking for. it tells you the total size

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...