Jump to content

Any way to make DirGetSize exclude hidden/system files?

Recommended Posts

I'm working on a script to copy a subset of files and folders from a PC to a server.  I'm using the extended info from DirGetSize to show how many files and folders and total size that will be copied (copy being done by RoboCopy).  Then I run DirGetSize against the destination when the copy is done to compare against the DirGetSize from the copy source so I can know if anything got skipped.  I'm finding that a lot of stuff is getting skipped.  This lead me to realize that it's because DirGetSize is including files and folders that are hidden and/or system, and I'm excluding these in RoboCopy.  Is there anyway to excluded these from DirGetSize?   I've been unable to find a UDF as yet, and I'd like to do something a little more elegant than piping the output from DIR into a file and reading that back.



Edited by bstjohn
Link to post
Share on other sites
#include <File.au3>

Local $aFiles = _FileListToArrayRec(@ScriptDir & "\", "*", $FLTAR_FILESFOLDERS, $FLTAR_RECUR)
Local $iFullSize = DirGetSize(@ScriptDir)

ConsoleWrite("Beginning size: " & ($iFullSize) / 1024 & @LF)    ; / 1024 to convert to kb, easier to read

For $i = 1 To $aFiles[0]
    Local $iAttributes = FileGetAttrib(@ScriptDir & "\" & $aFiles[$i])
    Local $iFileSize = FileGetSize(@ScriptDir & "\" & $aFiles[$i])
    Local $iDirSize = DirGetSize(@ScriptDir & "\" & $aFiles[$i])

    If (StringInStr($iAttributes, "S")) Then
        If (StringInStr($iAttributes, "D")) Then
            ConsoleWrite("Folder '" & $aFiles[$i] & "' is a system file, subtracting from full size" & @LF)
            $iFullSize -= $iDirSize
            ConsoleWrite("File '" & $aFiles[$i] & "' is a system file, subtracting from full size" & @LF)
            $iFullSize -= $iFileSize

ConsoleWrite("Adjusted size: " & ($iFullSize) / 1024 & @LF) ; / 1024 to convert to kb, easier to read

Something like this should get you going. You'll have to figure out a way to account for if the current file being checked is a directory and it's subtracted from the full size, to exclude all files under that directory. I didn't account for hidden because I believe hidden files are still copied. I could be wrong, if I am just add another StringInStr for "H".

Link to post
Share on other sites
3 hours ago, InunoTaishou said:

I didn't account for hidden because I believe hidden files are still copied. I could be wrong, if I am just add another StringInStr for "H".

RoboCopy's /XA switch let's you pick which attributes to exclude, so I'm excluding system and hidden.  So I'll add another StringInStr for "H" and that'll do it.

This puts me on a good track.  Thanks for the mental kickstart!

Link to post
Share on other sites


I've found that _FileListToArray() has the inherent ability to filter the system and hidden files:

Add one or more of the following to $iReturn to omit files/folders with that attribute
+ $FLTAR_NOHIDDEN (4) - Hidden files and folders
+ $FLTAR_NOSYSTEM (8) - System files and folders
+ $FLTAR_NOLINK (16) - Link/junction folders

That makes things all the easier.  Thanks for pointing me in the right direction.

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By morion84
      Hi, when I call a MsgBox function I can use a "$MB_SERVICE_NOTIFICATION" flag so it will be displayed "on the current active desktop, even if there is no user logged on to the computer.". That works just great. Is there a way to do the same to Autoit GUI Form so it will be visible on desktop even if running from system account and user is not logged?
    • By rudi
      for some script I need to investigate the states checked/unchecked, hidden/shown, enabled/disabled to several checkbox controls.
      Any suggestions to this script to retrieve the information in a better way?
      ; Autoit Version ; GuiCtrlCheckState.au3 #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $CtrlW = 100 $CtrlH = 30 $GuiW = 250 $GuiH = 300 GUICreate("Test Checkbox Status", $GuiW, $GuiH) $Ctrl = GUICtrlCreateCheckbox("Checkbox", 10, 10, $CtrlW, $CtrlH) Opt("Guicoordmode", 2) $BtnDisable = GUICtrlCreateButton("Disable", -1, 10) $BtnEnable = GUICtrlCreateButton("Enable", -1, 1) $BtnHide = GUICtrlCreateButton("Hide", 10, -$CtrlH * 2 - 1) $BtnUnHide = GUICtrlCreateButton("Show (Unhide)", -1, 1) $BtnCheckChecked = GUICtrlCreateButton("IsChecked", -$CtrlW * 2 - 10, 40) $BtnCheckEnabled = GUICtrlCreateButton("IsEnabled", -1, 1) $BtnCheckHidden = GUICtrlCreateButton("IsHidden", -1, 1) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $BtnDisable GUICtrlSetState($Ctrl, $gui_disable) Case $BtnEnable GUICtrlSetState($Ctrl, $GUI_Enable) Case $BtnHide GUICtrlSetState($Ctrl, $GUI_Hide) Case $BtnUnHide GUICtrlSetState($Ctrl, $GUI_show) Case $BtnCheckChecked If CheckState($Ctrl, $GUI_CHECKED) Then ConsoleWrite("Checked" & @CRLF) Else ConsoleWrite("not checked" & @CRLF) EndIf Case $BtnCheckEnabled If CheckState($Ctrl, $GUI_Enable) Then ConsoleWrite("enabled" & @CRLF) Else ConsoleWrite("disabled" & @CRLF) EndIf Case $BtnCheckHidden If CheckState($Ctrl, $GUI_Hide) Then ConsoleWrite("Hidden" & @CRLF) Else ConsoleWrite("not hidden" & @CRLF) EndIf EndSwitch WEnd Func CheckState($_CtrlID, $_State = $GUI_CHECKED) ConsoleWrite("---------------------" & @CRLF) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_State to check = ' & $_State & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $_Read = GUICtrlRead($_CtrlID) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_Read (GuiCtrlRead) = ' & $_Read & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $_StateFound = GUICtrlGetState($_CtrlID) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_StateFound (GuiCtrlGetState) = ' & $_StateFound & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console If $_StateFound = -1 Then MsgBox(48, "Control-ID not defined", "Control-ID invalid") Return False ElseIf BitAND($_StateFound, $_State) = $_State Then Return True ElseIf BitAND($_Read, $_State) = $_State Then Return True Else Return False EndIf EndFunc ;==>CheckState Regards, Rudi.
    • By BlazerV60
      Hello all,
      I've been trying to figure out how to launch Google Chrome in the background (hidden) but it doesn't seem possible. I've tried the following methods:
      ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "", "", "", @SW_HIDE) Also I've tried:
      ShellExecute(@ComSpec, "/c start chrome.exe","","",@SW_HIDE) Lastly I tried:
      RunWait('"'&@ProgramFilesDir&'\Google\Chrome\Application\chrome.exe" --silent-launch',@ScriptDir)  
      But all of them launch my chrome browser without hiding it. Does anyone know a workaround for this or if AutoIT just can't Chrome? 
      Bonus points if you know how to make it launch chrome hidden and make it go to https://www.autoitscript.com
      Thank you,
    • By nacerbaaziz
      Hi dear
      I have a question
      about the display language of the system
      How can I get the current display language and how can I change it by autoit
      Of course, if this is possible
      Greetings to all and hope you help me
    • By nss
      Hi all,
      I'm making an app that among other things has the system info feature, where it displays stuff like the system version, build, CPU and ram stats, etc.
      So, I haven't been able to find anywhere a way to access the following things (is there even?):
      Windows version (not like WIN_10, but the version like 1607, or 1511 Windows edition like professional, home, education, etc. information whether the Windows is registered or not (optionally the registrant's name) the type of the currently logged-in user (e.g., administrator) computer manufacturer and model (e.g., dell inc. Inspiron n5110 boot mode (e.g., safe, normal) CPU tempreture I'd appreciate a lot if any of you could help me with any of the things from above; it would mean a lot to me.
      Have a great day.
  • Create New...