SoulA Posted January 7, 2011 Share Posted January 7, 2011 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 More sharing options...
nitekram Posted January 7, 2011 Share Posted January 7, 2011 DriveSpaceTotal ( "path" ) 2¢ 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." 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 More sharing options...
SoulA Posted January 7, 2011 Author Share Posted January 7, 2011 DriveSpaceTotal ( "path" )That gives me the total size of the disk that a file/folder is located on... not really what I'm looking for unless this is a clue to something I'm missing. Link to comment Share on other sites More sharing options...
Varian Posted January 7, 2011 Share Posted January 7, 2011 What you are looking for is the relationship for file size to cluster size. Look Link to comment Share on other sites More sharing options...
guinness Posted January 7, 2011 Share Posted January 7, 2011 (edited) 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 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 Edited January 7, 2011 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Varian Posted January 7, 2011 Share Posted January 7, 2011 (edited) 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 Swissshhhh!!!! Edited January 7, 2011 by Varian Link to comment Share on other sites More sharing options...
guinness Posted January 7, 2011 Share Posted January 7, 2011 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
SoulA Posted January 7, 2011 Author Share Posted January 7, 2011 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 More sharing options...
guinness Posted January 7, 2011 Share Posted January 7, 2011 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Varian Posted January 7, 2011 Share Posted January 7, 2011 It was a quick edit, but I saw the use of incorrect tags So you're not that Swissshhhh!!!!Rain on my parade Link to comment Share on other sites More sharing options...
SoulA Posted January 7, 2011 Author Share Posted January 7, 2011 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 More sharing options...
SoulA Posted January 7, 2011 Author Share Posted January 7, 2011 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 More sharing options...
SoulA Posted January 7, 2011 Author Share Posted January 7, 2011 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 More sharing options...
guinness Posted January 7, 2011 Share Posted January 7, 2011 Nice Function Deathbringer, added to the Function Folder! 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Ascend4nt Posted January 7, 2011 Share Posted January 7, 2011 (edited) 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). expandcollapse popup#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 January 7, 2011 by Ascend4nt My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
KaFu Posted January 7, 2011 Share Posted January 7, 2011 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 ...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_DFSIO_REPARSE_TAG_DFSRIO_REPARSE_TAG_HSMIO_REPARSE_TAG_HSM2IO_REPARSE_TAG_MOUNT_POINTIO_REPARSE_TAG_SISIO_REPARSE_TAG_SYMLINK OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Ascend4nt Posted January 7, 2011 Share Posted January 7, 2011 (edited) 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 January 7, 2011 by Ascend4nt My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
KaFu Posted January 7, 2011 Share Posted January 7, 2011 I knew I already read it somewhere, found the MSDN article again: "There are three types of file links supported in the NTFS file system: hard links, junctions, and symbolic links." OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
SoulA Posted January 7, 2011 Author Share Posted January 7, 2011 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). expandcollapse popup#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 More sharing options...
Cars0n66 Posted January 7, 2011 Share Posted January 7, 2011 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now