Sign in to follow this  
Followers 0
Raffav

Get the Largest file in the current directory

25 posts in this topic

Hello,

i am new on autoit script

i want to make a script that get the size of a file(the name of it, will be a variable inputed by a parameter) in current running directory (where the script is located) than will check if the size is => ei: 1Gb will pop up msgbox

ie:

scritp.ext namefile "another parameter"

Thanks

sorry for bad engish

Share this post


Link to post
Share on other sites



Look in the help file for the commands:

_FileListToArray

FileGetSize

MsgBox


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Raffav,

Welcome to the AutoIt forum. ;)

What you want to do is very easy - take a look at the following in the Help file and you should be able to put something together:

@ScriptDir - Where the script is located

_FileListToArray - Get a list of the files in a folder

For..Next - Loop through those files

FileGetSize - Get the size of each file

If...EndIf - Check if the file is > 1Gb

MsgBox - Show the result.

Give it a go and see how you get on - you know where we are if you run into difficulties. :)

M23


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

Thanks,

i will post son with some result or no ;)

Share this post


Link to post
Share on other sites

Here to start with

#include <File.au3>
#include <Array.au3>
$dirPath = "C:UsersMarkoDesktoptest"
$fileArray = _FileListToArray($dirPath)
$fileSize = 0
$size = 0
$fileName = ""
For $i = 1 to UBound($fileArray) - 1
  
   $fileSize = FileGetSize($fileArray[$i])
  
   If $fileSize > $size Then
  
   $size = $fileSize
   $fileName = $fileArray[$i]
  
   EndIf
  
Next
MsgBox(0, "Largest file", "Largest file is " & $fileName)

Share this post


Link to post
Share on other sites

searchresult,

I see the "give a man a fish" versus "give a man a net" argument is lost on you. ;)

M23


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

here what i get and is almost what i want

it is for control the size of the Outlook pst

now i what to when the pst get >= 10GB it pop a gui with the msg saying some text but the windows must have minimize mazimize and X desable so user cant ignore it, need to click ON Exit buttons

If $CMDLINE[0] = 0 Then
    ; parameter needed
    MsgBox(0,"", "parametro necessario")
    Exit
EndIf
;~     Else
Local $size = FileGetSize($CMDLINE[1])
if $size = 0 Then
    ; file not found/insert
    MsgBox(0,"","arquivo não encontrado/informado")

ElseIf $size >= "945804" Then
    ; new pst needed
    MsgBox(0,"","nova pst necessaria "&$size)

ElseIf $size >= "438412" Then
    ; pst near to limit
    MsgBox(0,"","Pst chegando no limite "&$size)

ElseIf $size >= "356087" Then
    ; pst OK
    MsgBox(0,"","PST OK "&$size)
EndIf

Share this post


Link to post
Share on other sites

Look at the GUICreate style of $WS_POPUP


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks, I will give a look on it.

And later I will ask to change the title name, is no more what I am looking for.

Later with new info/question.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Another, likely very fast, way to peg which file is largest in a directory:

#include <Constants.au3>
Global $sDirectory = @WindowsDir, $sStdOut
$PID = Run(@ComSpec & ' /c DIR "' & $sDirectory & '" /B /A-D /O-S', "", @SW_HIDE, $STDOUT_CHILD)
While Not @error
    $sStdOut &= StdoutRead($PID)
WEnd
$sStdOut = StringLeft($sStdOut, StringInStr($sStdOut, @CRLF) - 1)
MsgBox(0, $sDirectory, "Largest file: " & $sStdOut)

Edit: Change the "$sStdOut = " statemnet near the end to a StringSplit() and you'd have an array sorted by filesize. You could parse that and only have to call FileGetSize() for those files that meet the minimum filesize requirement (with the exception of the one FileGetSize() call that read the first file below the minimum size, causing an exit from the loop).

Edit2: I suppose avoiding any FileGetSize() calls would be better:

#include <Array.au3> ; for testing
#include <Constants.au3>
Global $sDirectory = @WindowsDir, $iMinSize = 500000, $sStdOut, $iIndex = 0

$PID = Run(@ComSpec & ' /c DIR "' & $sDirectory & '" /A-D /-C /O-S', "", @SW_HIDE, $STDOUT_CHILD)
While Not @error
    $sStdOut &= StdoutRead($PID)
WEnd
$aStdOut = StringSplit($sStdOut, @CRLF)

For $x = 1 To $aStdOut[0] ; pack and (partially) format array
    If StringMid($aStdOut[$x], 3, 1) = "/" Then
        $aStdOut[$x] = StringStripWS($aStdOut[$x], 7)
        $aStdOut[$x] = StringTrimLeft($aStdOut[$x], StringInStr($aStdOut[$x], " ", 2, 3))
        If $aStdOut[$x] < $iMinSize Then ExitLoop
        $iIndex += 1
        $aStdOut[$iIndex] = $aStdOut[$x]
    EndIf
Next
$aStdOut[0] = $iIndex
ReDim $aStdOut[$iIndex + 1]

_ArrayDisplay($aStdOut, "Files > " & $iMinSize) ; for testing

I am guilty sometimes of providing the net, but I've left holes in this, and the OP has posted original code showing he's making the effort ;)

Edited by Spiff59

Share this post


Link to post
Share on other sites

Look at the GUICreate style of $WS_POPUP

sorry but i cant find any reference for $ws_popup in help file

Share this post


Link to post
Share on other sites

Read the entire sentence.

Step 1 - Read the help file for information about GUICreate

Step 2 - Look at the styles for GUICreate and find $WS_POPUP, there's a hyperlink in the help file under GUICreate for the styles and extended styles for the function.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Read the entire sentence.

Step 1 - Read the help file for information about GUICreate

Step 2 - Look at the styles for GUICreate and find $WS_POPUP, there's a hyperlink in the help file under GUICreate for the styles and extended styles for the function.

Yes i already fount it, but i dont know/have success to make the pop up with right conner windows "_ |_| X desable "

Share this post


Link to post
Share on other sites

The ws_popup style doesn't have those controls on the GUI, so there's no need to disable them. If for some reason you want those controls on the GUI but they are disabled then you're going to have to search for the numerous examples in the forum for that as I can't recall how it's done.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

it will be something like that?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ###
$Form1 = GUICreate("pst alert", 431, 156,$WS_POPUP)
$Edit1 = GUICtrlCreateEdit("", 8, 16, 409, 97)
GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("Button1", 24, 120, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 144, 120, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
e

EDIT1 i down know the name but in the autoitscript Editor has a hot key that organize the scirpt like

ie:

if something then

some string

else

another string

endfi

Edited by Raffav

Share this post


Link to post
Share on other sites

How i said i am a very noob in autoit (traying to find answer in the forum/google)

Yes is a mess

i want when a if is (True) meet it show up a gui box with a edit box (readonly)

with only one if i have maked work but i put elseif or else i cant make work

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#Region ### START Koda GUI section ###
$Form1 = GUICreate("pst alert", 431, 156)
$Edit1 = GUICtrlCreateEdit("", 8, 16, 409, 97,$WS_VSCROLL)
;GUICtrlSetData(-1,"teste")
$Button1 = GUICtrlCreateButton("Button1", 24, 120, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 144, 120, 75, 25)
;GUISetState(@SW_SHOW)
_GUICtrlEdit_SetReadOnly($Edit1, True)
#EndRegion ### END Koda GUI section ###
If $CMDLINE[0] = 0 Then
; paramet needed
;MsgBox(0,"", "parametro necessario")
GUISetState(@SW_SHOW)
GUICtrlSetData($Edit1, "Parametro Necessário")
;Exit
;Else
;~ While 1
;~ $nMsg = GuiGetmsg()
;~  Switch $nMsg
;~   Case $GUI_EVENT_CLOSE
;~    Exit
;~   case $Button1
;~    Exit
;~   case $Button2
;~    Exit
;~  EndSwitch
;~ WEnd
Local $size = FileGetSize($CMDLINE[1])
if $size = 0 Then
; file not found/insert
;~  MsgBox(0,"","arquivo não encontrado/informado")
GUISetState(@SW_SHOW)
GUICtrlSetData($Edit1, "Parametro Necessário22")
ElseIf $size >= "945804" Then
; new pst needed
;MsgBox(0,"","nova pst necessaria "&$size)
GUISetState(@SW_SHOW)
ElseIf $size >= "438412" Then
; pst near to limit
;MsgBox(0,"","Pst chegando no limite "&$size)
GUISetState(@SW_SHOW)
ElseIf $size >= "356087" Then
; pst OK
;MsgBox(0,"","PST OK "&$size)
GUISetState(@SW_SHOW)

While 1
$nMsg = GuiGetmsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
     Exit
;~   case $Button1
;~    Exit
;~   case $Button2
;~    Exit
EndSwitch
WEnd
EndIf
EndIf

Share this post


Link to post
Share on other sites

Hello

i again

and if i want to get the smallest file ? that have extension ".PST"

i try to figured out using this one but i cant understand how it work so i cant change to smallest

#include <File.au3>
#include <Array.au3>
$dirPath = "C:UsersMarkoDesktoptest"
$fileArray = _FileListToArray($dirPath)
$fileSize = 0
$size = 0
$fileName = ""
For $i = 1 to UBound($fileArray) - 1
 
   $fileSize = FileGetSize($fileArray[$i])
 
   If $fileSize > $size Then
 
   $size = $fileSize
   $fileName = $fileArray[$i]
 
   EndIf
 
Next
MsgBox(0, "Largest file", "Largest file is " & $fileName)

Share this post


Link to post
Share on other sites

Raffav,

Look at the _FileListToArray command in the Help file to see how to limit the returns to only "*.pst" files. :)

As to the smallest file - you need something like this:

$fileName = ""
$size = 1e10 ; Set a big number to start with
For $i = 1 to UBound($fileArray) - 1

   $fileSize = FileGetSize($fileArray[$i])
   If $fileSize < $size Then ; Now see if this file is even smaller
        $size = $fileSize
        $fileName = $fileArray[$i]
   EndIf
Next
MsgBox(0, "Smallest file", "Smallest file is " & $fileName)

All clear? ;)

M23

1 person likes this

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

Raffav,

Look at the _FileListToArray command in the Help file to see how to limit the returns to only "*.pst" files. :)

As to the smallest file - you need something like this:

$fileName = ""
$size = 1e10 ; Set a big number to start with
For $i = 1 to UBound($fileArray) - 1

   $fileSize = FileGetSize($fileArray[$i])
   If $fileSize < $size Then ; Now see if this file is even smaller
        $size = $fileSize
        $fileName = $fileArray[$i]
   EndIf
Next
MsgBox(0, "Smallest file", "Smallest file is " & $fileName)

All clear? ;)

M23

thanks alot i was getting close to your solution kkkk

and i already find the way to filter for *.pst

the help file is a GOD help kkk

Share this post


Link to post
Share on other sites

Hello again

i think the way is using arrays but i cant find how to

how to get the 2,ou 3, N smalest file, with the size corresponding to the file name

Thanks Again

sorry for Bad english

Raffav

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