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 comment
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
        Else
            ConsoleWrite("File '" & $aFiles[$i] & "' is a system file, subtracting from full size" & @LF)
            $iFullSize -= $iFileSize
        EndIf
    EndIf
Next

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 comment
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 comment
Share on other sites

InunoTaishou-

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

×
×
  • Create New...