Jump to content

File count and total


Recommended Posts

I am after some help, I have been playing with the _filelisttoarray but it is a bit beyond me.

I am trying to get a total size of the file types in a folder and it's sub directories and output this to a text file. I am also trying to collect information on the largest file of a particular type and include this in the results.

output would be along the lines of

.doc total 123456kb

.doc largest 23456kb

.xls total 654321kb

.xls largest 65432kb

and so on.

All help is appreciated.

Link to comment
Share on other sites

Take it one step at a time.

What problems are you having with _filelisttoarray()?

Once you are comfortable with that you can look at and use which will search subdirectories also.

But like I say, one step at a time.

EDIT:

Link to Melba32 UDF

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

First you need to do rile list to array.

Then you need to redim the array so it has more dimensions (storing the size for each file)

Then you need to get the file size for each file and save that to another subscript in the array.

Then you need to use string split () or stinginstr() to find the file type.

Then, you can add the results together and voila! (probably need and array of the different file types too)

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

I have managed to start listing files in to an array - by using the example code from the help file, but I am not able to get the file size information.

Ok, start simple, post your code for file list, you say you are not able to get the file size? how come? have you tried to?

post what code you have so far.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

This is what I have started with. I know it is very basic, but we all have to start somewhere :-) $sz was used to try and set the size of the $a array but it did not like it

#Include <File.au3>

#Include <Array.au3>

dim $z

$FileList=_FileListToArray("c:\")

If @Error=1 Then

MsgBox (0, " ", "Error. ")

Exit

EndIf

MsgBox(0, "array 2", $Filelist[0])

dim $sz = $FileList[0]

dim $a[100]

for $z = 0 to ($FileList[0])

$a[$z] = FileGetSize("c:\" & $FileList[$z])

next

MsgBox(0, "array 2", $a[2])

_ArrayDisplay($FileList, "$FileList ")

_ArrayDisplay($a, "Sizes ")

Edited by Mattcarr
Link to comment
Share on other sites

Its quite a decent start.

Next step is to filter file extensions.

here is a very basic addition to your script to give you an idea.

#include <File.au3>
#include <Array.au3>
Dim $z

$filefolder = FileSelectFolder("Select a folder", @HomeDrive) & "\" ;get a folder into a variable
$fileextension = "*." & InputBox("Choose extension", "eample 'txt'", "exe");same with extension

$FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
If @error = 1 Then
    MsgBox(0, "Error", "_FileListToArray "); good practice to show where your errors are coming from, will help as script grows
    Exit
EndIf
MsgBox(0, "array 2", $FileList[0])
Dim $sz = $FileList[0]
Dim $a[100]
For $z = 0 To ($FileList[0])
    $a[$z] = FileGetSize($filefolder & $FileList[$z])
Next
MsgBox(0, "array 2", $a[2])


_ArrayDisplay($FileList, "$FileList ")
_ArrayDisplay($a, "Sizes ")
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I have had a play and I think I understand how this is working -

#include <File.au3>
#include <Array.au3>
Dim $z
Dim $y

$filefolder = FileSelectFolder("Select a folder", @HomeDrive) & "\" ;get a folder into a variable
$fileextension = "*." & InputBox("Choose extension", "eample 'txt'", "exe");same with extension

$FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
If @error = 1 Then
    MsgBox(0, "Error", "_FileListToArray "); good practice to show where your errors are coming from, will help as script grows
    Exit
EndIf
MsgBox(0, "array 2", $FileList[0])
$sz = ubound($FileList)
Dim $a[$sz]
For $z = 0 To ($FileList[0])
    $a[$z] = FileGetSize($filefolder & $FileList[$z])
Next
MsgBox(0, "array 2", $a[2])


_ArrayDisplay($FileList, "$FileList ")
_ArrayDisplay($a, "Sizes ")

all I need to do is to expand on it now - again all help is appreciated

Edited by Mattcarr
Link to comment
Share on other sites

the next iteration now counts up the sizes and gives me the maximum file size, got to work out how to put this in to a text file

#include <File.au3>
#include <Array.au3>
Dim $z
Dim $y

$filefolder = FileSelectFolder("Select a folder", @HomeDrive) & "\" ;get a folder into a variable
$fileextension = "*." & InputBox("Choose extension", "eample 'txt'", "exe");same with extension

$FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
If @error = 1 Then
    MsgBox(0, "Error", "_FileListToArray "); good practice to show where your errors are coming from, will help as script grows
    Exit
EndIf
;MsgBox(0, "array 2", $FileList[0])
$sz = ubound($FileList)
Dim $a[$sz]
For $z = 0 To ($FileList[0])
    $a[$z] = FileGetSize($filefolder & $FileList[$z])
Next
;MsgBox(0, "array 2", $a[2])


;_ArrayDisplay($FileList, "$FileList ")
;_ArrayDisplay($a, "Sizes ")

; an attempt to total the file sizes and to know and list the largest file size and it's name
$tot = 0
$max = 0
for $z = 0 to ($FileList[0])
    if $a[$z] > $max then $max = $a[$z]
        $tot = $tot + $a[$z]
    Next
    
MsgBox(0, "Total" , $tot)
MsgBox(0, "Max" , $max)
Edited by Mattcarr
Link to comment
Share on other sites

was going to sugest making a 2d array from you others

#include <File.au3>
#include <Array.au3>
Dim $z
Dim $y

$filefolder = FileSelectFolder("Select a folder", @HomeDrive) & "\" ;get a folder into a variable
$fileextension = "*." & InputBox("Choose extension", "eample 'txt'", "au3");same with extension

$FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
If @error = 1 Then
    MsgBox(0, "Error", "_FileListToArray "); good practice to show where your errors are coming from, will help as script grows
    Exit
EndIf
MsgBox(0, "array 2", $FileList[0])
$sz = UBound($FileList)
Dim $a[$sz]
$a[0] = $sz - 1
For $z = 1 To ($FileList[0])
    $a[$z] = FileGetSize($filefolder & $FileList[$z])
Next
MsgBox(0, "array 2", $a[2])


_ArrayDisplay($FileList, "$FileList ")
_ArrayDisplay($a, "Sizes ")

; merge arrays into a 2D array

Dim $2D_FileAndSizeArray[$sz][2]; create array with same indexes as one of the others
$2D_FileAndSizeArray[0][0] = $sz - 1 ; set first element to the number of results

For $i = 1 To $sz - 1;loop through them
    $2D_FileAndSizeArray[$i][0] = $FileList[$i];make colum 1 == the filename
    $2D_FileAndSizeArray[$i][1] = $a[$i];make colum 2 == the size
Next

_ArrayDisplay($2D_FileAndSizeArray)

Also you should put your code into tags.

If you press reply to this post, you will see how.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Thanks for the help on making the 2D array.

I have added a bit to out out some results to a text file

#include <File.au3>
#include <Array.au3>
Dim $z

$filefolder = FileSelectFolder("Select a folder", @HomeDrive) & "\" ;get a folder into a variable
$fileextension = "*." & InputBox("Choose extension", "eample 'txt'", "exe");same with extension

$FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
If @error = 1 Then
    MsgBox(0, "Error", "_FileListToArray "); good practice to show where your errors are coming from, will help as script grows
    Exit
EndIf
$sz = ubound($FileList)
Dim $a[$sz]
For $z = 0 To ($FileList[0])
    $a[$z] = FileGetSize($filefolder & $FileList[$z])
Next
;_ArrayDisplay($FileList, "$FileList ")
;_ArrayDisplay($a, "Sizes ")

; merge arrays into a 2D array

Dim $2D_FileAndSizeArray[$sz][2]; create array with same indexes as one of the others
$2D_FileAndSizeArray[0][0] = $sz - 1 ; set first element to the number of results

For $i = 1 To $sz - 1;loop through them
    $2D_FileAndSizeArray[$i][0] = $FileList[$i];make colum 1 == the filename
    $2D_FileAndSizeArray[$i][1] = $a[$i];make colum 2 == the size
Next

;_ArrayDisplay($2D_FileAndSizeArray)

; an attempt to total the file sizes and to know and list the largest file size and it's name
$tot = 0
$max = 0
for $z = 0 to ($FileList[0])
    if $2D_FileAndSizeArray[$z][1] > $max then $max = $2D_FileAndSizeArray[$z][1]
        $tot = $tot + $2D_FileAndSizeArray[$z][1]
    Next
; convert results in to MB equivilent
$tot = ($tot / 1048576)
$max = ($max / 1048576)

MsgBox(0, "Total" , $tot)
MsgBox(0, "Max" , $max)

; put this in to a text file
$file = FileOpen("c:\info.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, "Document Type : ")
FileWrite($file, $fileextension & @CRLF)
FileWrite($file, "Total Number of Files : ")
FileWrite($file, $FileList[0] & @CRLF)
FileWrite($file, "Average File Size : ")
$avg = ($tot / $FileList[0])
FileWrite($file, $avg & @CRLF)
FileWrite($file, "Total Size of Files : ")
FileWrite($file, $tot & @CRLF)
FileWrite($file, "Maximum File Size : ")
FileWrite($file, $max & @CRLF)

FileClose($file)

I would like to be able to have it search for the file types in the sub folders of the selected file - any hints on how to do this?

Edited by Mattcarr
Link to comment
Share on other sites

Yes, I linked Melba23s UDF in post #2

Melba23 is very thougrer with his explaining of his UDF so I'm sure you will find your way.

Before you dive in head first, I suggest to take what you have and make a couple of functions out of it, to create some tidy structure.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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