Sign in to follow this  
Followers 0
Chimaera

File type, wildcard and size search

10 posts in this topic

Ok im trying to do a checkbox that when it is ticked then gives me an approximate size of the item of the checkbox type

So for example ignoring the checkbox bit for the moment

say i choose drive c:\ and i have the need to know the total size of the mp3's that are on that drive

I looked at FileGetSize but it wont do directory's, so i tried this

$drive = "C:\"
$size = DirGetSize($drive & "*.mp3")
Msgbox(0,"","Size: " & Round($size / 1024 / 1024 / 1024 ) & "  GB")

But it doesn't like the wildcard, $drive on its own works fine but i need the total of the wildcarded mp3's

Any suggestions which way to go?

Thanks

Chimaera

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Chimaera,

Use my RecFileListToArray UDF to get an array of all the .mp3 files on the drive - then loop through them using FileGetSize. :unsure:

M23

Edit: This works fine for me:

#include <Array.au3>
#include <RecFileListToArray.au3>

$sRoot = "M:\Music\MP3\"

$aListing = _RecFileListToArray($sRoot, "*.mp3", 1, 1)

$nSize = 0
For $i = 1 To $aListing[0]
    $nSize += FileGetSize($sRoot & $aListing[$i]) / 1048576
Next

MsgBox(0, "Total", Round($nSize, 2) & "Mb")

And the total is not too far removed from that returned by my file manager. :>

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Does it support just drive selection? when i try this it dosent work

#include <Array.au3>
#include <File.au3>
#include "RecFileListToArray.au3"  

Local $aArray, $drive 
$drive = "C:\" 
$type = ".mp3" 
$aArray = _RecFileListToArray($drive, $type, 0, 1, 1) 

_ArrayDisplay($aArray)

Or have i done something wrong?

and is FileGetSize($array) the correct way to use an array with FileGetSize? as i really dont use arrays with the stuff i do

EDIT

sorry you posted just before i did

Thx for the help

Edited by Chimaera

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Chimaera,

Or have i done something wrong?

Yup! :D

$type = "*.mp3" ; Do not forget the wildcard

is FileGetSize($array) the correct way

No, you need to use a loop as I showed in the example I posted above. :unsure:

If you are not comfortable with arrays, then I recommend the Arrays tutorial in the Wiki. Arrays are a fundamental part of coding and you should at least understand the basics of how they work as many AutoIt functions use them as return values. ;)

M23

Edit: Glad you got it sorted. :>

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

One small other thought, there are some windows .mp3s i will need to exclude they have known names so i can easily do a list

Now i see from the udf that this is required

$sExclude_List = "First.mp3";"second.mp3" etc

But at what point do i include the excludes if that makes sense lol

Just thought is it possible to search for more than one type of music?

for eg

$aListing = _RecFileListToArray($sRoot, "*.mp3","*.wma", 1, 1)?

Edited by Chimaera

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Chimaera,

You need to include the excludes (:unsure:) when you call the function - like this:

$aListing = _RecFileListToArray($sRoot, "*.mp3", 1, 1, 0, 1, "First.mp3;Second.mp3")

Note the syntax - you only need a single pair of quotes around the list of excludes, with semicolons between them. :D

How many excludes will you have? If there are quite a few you might be better removing them from the returned array rather than excluding them from the listing function itself - let me know if you want some help along those lines. :>

M23

Edit:

Just thought is it possible to search for more than one type of music? for eg

$aListing = _RecFileListToArray($sRoot, "*.mp3","*.wma", 1, 1)?

Yes, you can do that but you need to use the correct syntax as I explained above:

$aListing = _RecFileListToArray($sRoot, "*.mp3;*.wma", 1, 1)

All clear? ;)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

How many excludes will you have? If there are quite a few you might be better removing them from the returned array rather than excluding them from the listing function itself - let me know if you want some help along those lines. :unsure:

M23

something like this for vista

"Kalimba.mp3" "Maid with the Flaxen Hair.mp3" "Sleep Away.mp3" "Amanda.wma" "Despertar.wma" "Din Din Wo (Little Child).wma" "Din Din Wo (Little Child).wma" "Distance.wma" "I Guess You're Right.wma" "I Ka Barra (Your Work).wma" "Love Comes.wma" "Muita Bobeira.wma" "OAM's Blues.wma" "One Step Beyond.wma" "Symphony_No_3.wma"

and for xp

"Beethoven's Symphony No. 9 (Scherzo).wma" "New Stories (Highway Blues).wma"

something of that nature there maybe the odd one or two extra

Im not sure if you spotted this edit on my last post

Just thought is it possible to search for more than one type of music?

for eg

$aListing = _RecFileListToArray($sRoot, "*.mp3","*.wma", 1, 1)? is that correct

Thanks for the help and advice, i think the double answering didnt help lol

Edited by Chimaera

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Here's the final code

Gives total for all music off common formats on drive with exceptions of all windows music

#include <Array.au3>
#include <RecFileListToArray.au3>

$sRoot = "C:\"

$aListing = _RecFileListToArray($sRoot, "*.3gp;*.aiff;*.aac;*.alac;*.dct;*.flac;*.m4p;*.mpc;*.mp3;*.ogg;*.ra;*.rm;*.wma", 1, 1, "Kalimba.mp3;Maid with the Flaxen Hair.mp3;Sleep Away.mp3;Amanda.wma;Despertar.wma;Din Din Wo (Little Child).wma;Distance.wma;I Guess You're Right.wma;I Ka Barra (Your Work).wma;Love Comes.wma;Muita Bobeira.wma;OAM's Blues.wma;One Step Beyond.wma;Symphony_No_3.wma;Beethoven's Symphony No. 9 (Scherzo).wma;New Stories (Highway Blues).wma")

$nSize = 0
For $i = 1 To $aListing[0]
    $nSize += FileGetSize($sRoot & $aListing[$i]) / 1048576
Next

MsgBox(0, "Total", Round($nSize, 2) & "  Mb")

Many thanks to Melba23 for the help

Edited by Chimaera

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Chimaera,

You are obviously looking to exclude the files that ship with Windows. As these are all in the same subfolder, you can do this easily by using the $sExclude_List_Folder parameter as explained in the function header and the thread lead post. ;)

This works for my Vista setup:

;
$aListing = _RecFileListToArray($sRoot, "*.mp3;*wma", 0, 1, 0, 1, "", "x86_microsoft-windows-musicsamples_31bf3856ad364e35_6.0.6000.16386_none_a81d9e66b53cd1c0")
;

It does make the line a little shorter! :>

M23

Edit: New forum software does not like long single lines of code. :unsure:

Edit: Although not by much it seems! :D

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

This is a little shorter

#include <Array.au3> 
#include <RecFileListToArray.au3> 
$sRoot = "c:\" 
$includes = '"*.3gp;*.aiff;*.aac;*.alac;*.dct;*.flac;*.m4p;*.mpc;*.mp3;*.ogg;*.ra;*.rm;*.wma"' 
$excludes = '"Kalimba.mp3;Maid with the Flaxen Hair.mp3;Sleep Away.mp3;Amanda.wma;Despertar.wma;Din Din Wo (Little Child).wma;Distance.wma;I Guess You?re Right.wma;I Ka Barra (Your Work).wma;Love Comes.wma;Muita Bobeira.wma;OAM?s Blues.wma;One Step Beyond.wma;Symphony_No_3.wma;Beethoven?s Symphony No. 9 (Scherzo).wma;New Stories (Highway Blues).wma"' 

$aListing = _RecFileListToArray($sRoot, $includes, 1, 1, $excludes)  

$nSize = 0 
For $i = 1 To $aListing[0]     
$nSize += FileGetSize($sRoot & $aListing[$i]) / 1048576 
Next  
MsgBox(0, "Total", Round($nSize /1024, 2) & "  Gb Of Music")
Edited by Chimaera

Share this post


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
Sign in to follow this  
Followers 0