Jump to content

Return File Size In MB :)


z0mgItsJohn
 Share

Recommended Posts

Heres My Newest Ideal :3 Well.. I Noticed That 'FileGetSize' Tells You The File Size In Bytes.. Well I Came Out With A Cool Function To Return The File Size In Mega Bytes!

~Enjoy~

(_FileSize.AU3)

$MegaByte = ('1048576')

Func _FileSize_In_MegaBytes ($File)
$FileSizeInBytes = FileGetSize ($File)
$Equal = $FileSizeInBytes / $MegaByte
$Round = Round ($Equal, '2')
Return $Round
EndFuncoÝ÷ Ù«­¢+Ø%¹±Õ±Ðí}¥±M¥é¹ÔÌÐì((ÀÌØíáµÁ±ô}¥±M¥é}}5   åÑÌ ÅÕ½ÐíèÀäÈí]¥¹½ÝÌÀäÈíU9M%AAL¹áÅÕ½Ðì¤()5Í  ½à À°ÅÕ½Ðí¥±M¥éÅÕ½Ðì°ÀÌØíáµÁ±µÀìÅÕ½Ðì5ÅÕ½Ðì°À

Please Feel Free To Post Questions.. Bugs.. Etc..

Edited by John2006

Latest Projects :- New & Improved TCP Chat

Link to comment
Share on other sites

Here is a function to return display size, so when it needed, it will return KB/MB/GB/TB...

ConsoleWrite(_GetDisplaySize(1023) & @LF) ; Bytes
ConsoleWrite(_GetDisplaySize(1548) & @LF) ; KBytes
ConsoleWrite(_GetDisplaySize(1024 * 1369) & @LF) ;MBytes
ConsoleWrite(_GetDisplaySize(1024 * 1024 * 1876) & @LF) ;GBytes
ConsoleWrite(_GetDisplaySize(1024 * 1024 * 1024 * 1656)) ;TBytes

Func _GetDisplaySize($iSize, $iPlaces = 2)
    Local $aBytes[5] = [' Bytes', ' KB', ' MB', ' GB', ' TB']
    For $i = 4 To 1 Step -1
        If $iSize >= 1024 ^ $i Then
            Return Round($iSize / 1024 ^ $i, $iPlaces) & $aBytes[$i]
        EndIf
    Next
    Return $iSize & ' Bytes'
EndFunc
Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Upgrade. Amount, what unit that is in, how many places to round the answer to, should it input as a string?, is the amount in bits?, should the output be in bits?, what unit to output to. If $outputUnit is negative, it's value serves as the maximum unit allowed, but will return the appropriate number otherwise.

for the units

0 = base

1 = kilo

2 = mega

3 = giga

4 = tera

5 = peta

6 = exa

7 = zetta

8 = yotta

9 = ?

Func ConvertSize($inputSize, $inputUnit = 0, $outputPlaces = 2, $outputString = True, $inputBits = False, $outputBits = False, $outputUnit = -4)
    Local $unitNames[9] = ["","K","M","G","T","P","E","Z","Y"]
    Local $bytes = $inputSize * 1024 ^ $inputUnit
    Local $b = "B"
    If $inputBits Then $bytes /= 8
    If $outputBits Then
        $bytes *= 8
        $b = "b"
    EndIf
    If $outputUnit < 0 Then
        Local $outputMax = Abs($outputUnit)
        $outputUnit = Int(Log($bytes)/Log(1024))
        If $outputUnit > $outputMax Then $outputUnit = $outputMax
    EndIf
    If $outputString Then
        Return String(Round($bytes / 1024 ^ $outputUnit, $outputPlaces)) & $unitNames[$outputUnit] & $b
    Else
        Return Round($bytes / 1024 ^ $outputUnit, $outputPlaces)
    EndIf
EndFunc
Edited by crzftx
Link to comment
Share on other sites

crzftx

Wow, it's use no loop, and it's so complicated :) - Nice!

It seems that this is affect only on the TeraBytes...

BTW, AutoIt can not handle with ExaByte values. it returns something like: 1.#QNAN

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

I used ConsoleWrite(ConvertSize(1023,8,2,True,False,False,-10) & @CRLF) and it worked just fine, returning 1023YB.

Yes, but what if we need to convert a bytes to YB? i mean if the data is came from some file, or from InetGetSize (the last one can not get such big size i think), or from inputbox etc.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Now I see what you mean, 9223372036854775807, (8EB) is the largest value AutoIt understands. That is the largest signed 64 bit integer... can I make it unsigned? that would bring it up to 18446744073709551615.

You can try to make it a float by adding .00 and then e10

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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