Get the Largest file in the current directory
#1
Posted 16 May 2012 - 03:13 PM
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
#2
Posted 16 May 2012 - 03:19 PM
_FileListToArray
FileGetSize
MsgBox
How to ask questions the smart way!
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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.
#3
Posted 16 May 2012 - 03:23 PM
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
Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display
RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items
#4
Posted 16 May 2012 - 04:04 PM
i will post son with some result or no
#5
Posted 16 May 2012 - 06:50 PM
#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)
#6
Posted 16 May 2012 - 06:56 PM
I see the "give a man a fish" versus "give a man a net" argument is lost on you.
M23
Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display
RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items
#7
Posted 16 May 2012 - 08:32 PM
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
#8
Posted 16 May 2012 - 09:02 PM
How to ask questions the smart way!
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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.
#9
Posted 17 May 2012 - 12:26 AM
And later I will ask to change the title name, is no more what I am looking for.
Later with new info/question.
#10
Posted 17 May 2012 - 02:48 AM
#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, 17 May 2012 - 07:01 AM.
#11
Posted 17 May 2012 - 04:10 PM
sorry but i cant find any reference for $ws_popup in help fileLook at the GUICreate style of $WS_POPUP
#12
Posted 17 May 2012 - 05:13 PM
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.
How to ask questions the smart way!
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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.
#13
Posted 17 May 2012 - 05:34 PM
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 "
#14
Posted 17 May 2012 - 05:49 PM
How to ask questions the smart way!
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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.
#15
Posted 17 May 2012 - 06:54 PM
#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 ###
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, 18 May 2012 - 12:26 PM.
#16
Posted 18 May 2012 - 11:09 PM
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
#17
Posted 04 June 2012 - 02:52 PM
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)
#18
Posted 04 June 2012 - 03:03 PM
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
- Raffav likes this
Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display
RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items
#19
Posted 04 June 2012 - 03:29 PM
thanks alot i was getting close to your solution kkkkRaffav,
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:All clear?$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)
M23
and i already find the way to filter for *.pst
the help file is a GOD help kkk
#20
Posted 11 June 2012 - 02:49 PM
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
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users






