Jump to content

Folder Size Script


Recommended Posts

I am trying to write a script that would take a snapshot of my C drive and save the name and size of each directory formatted in an easy to read manner to a txt file.

I would then like to take a second snapshot a few days later and compare it to the first snapshot for any changes in folders and size of folders.

I have been working with DirGetSize and the associated $array[0] = Size

$array[1] = Files count $array[2] = Dirs Count parameters as well as IniWrite but just cant seem to put it together. I am obviously a newb and way over my head. The forum has helped me before and I would appreciate it again if someone could get me started and point me in the right direction. Thanks.

Edited by fmen
Link to comment
Share on other sites

Include some code you have tried to write and people will be more willing to help :(. I will work on some code on my own but I want to see something from you.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Here ya go

#include <GUIConstants.au3>

; gives all attributes
RunWait(@ComSpec & " /c " & "dir " & @HomeDrive & "\" & "/s" & " > " & @TempDir & "\dir.txt","",@SW_HIDE)
SLEEP(2000)
Run('Notepad "' & @TempDir & '\dir.txt"')
Exit

**** This code was given to me. by (i think) Cyberslub and or Mhz... sorry, these guys have helped me alot and its hard to remember ??????

Hope this will help

Enjoy

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Here ya go

#include <GUIConstants.au3>

; gives all attributes
RunWait(@ComSpec & " /c " & "dir " & @HomeDrive & "\" & "/s" & " > " & @TempDir & "\dir.txt","",@SW_HIDE)
SLEEP(2000)
Run('Notepad "' & @TempDir & '\dir.txt"')
Exit

**** This code was given to me. by (i think) Cyberslub and or Mhz... sorry, these guys have helped me alot and its hard to remember ??????

Hope this will help

Enjoy

<{POST_SNAPBACK}>

That'll do. I dont know that he needed that much information, but it works :-P. I am currently working on something that wouldnt go quite so deep, but would still return the proper numbers for the files in the C:\ Drive.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Thanks for the quick replies...

That's a great little script. I would like a little less information written to the txt file, however.

Here was my feeble initial start....

$Cn= DirGetSize("C:", 2)
$C= DirGetSize("C:")
$Windows = DirGetSize("C:\Windows")
;;;etc

Run("Notepad")

Winactivate ("Notepad", "")
Sleep (500)
Send ('Total Directories:{TAB} ')
Send ( $Cn )

Send ('Directory Size C:{TAB} ')
Send ($C)

;Etc

The problem is in getting all of the directories listed and then comparing the two files for differences.

I will work on the example provided..thanks

Link to comment
Share on other sites

Got it with the help of gafrost. For some reason the examples from the helpfile were giving me some problems and gafrost with a creative mind worked around them.

Here is the working code.

Dim $search, $file
Dim $dirSize, $dirFile, $dir = "c:\"
Dim $i, $line, $attrib


;Opens the file to write the desired output to.
$dirFile = FileOpen("output.txt", 1)

If $dirFile = -1 Then
    MsgBox(0, "Error", "The file output.txt was unable to be opened.")
    Exit
EndIf

; Shows the filenames of all files in the current directory, note that "." and ".." are returned.
$search = FileFindFirstFile($dir & "*.*")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

;MsgBox(0, "$search", $search)

While 1
    $file = FileFindNextFile($search)
   If @error Then
       ;MsgBox(0, "Error", "There are no more files/directories")
        ExitLoop
    EndIf
   $attrib = FileGetAttrib($dir & $file)
    If $attrib == "" Then
       ;MsgBox(4096,"Error", "Could not obtain attributes from " & $file)
;~       Exit
    Else
        If StringInStr($attrib, "D") Then
            $dirSize = DirGetSize($dir & $file, 1)
            $line = "Filename: " & $file & "   " & "DirSize(MB): " & Round($dirSize[0]/1024/1024) & "   " & "NumFiles: " & $dirSize[1] & "   " & "NumDirectories: " & $dirSize[2]
            FileWriteLine($dirFile, $line)
        EndIf
    EndIf
WEnd

; Close the search handle
FileClose($search)
FileClose($dirFile)

I think that should give you the information you want.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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