Sign in to follow this  
Followers 0
Targus

get filesize in array

5 posts in this topic

#1 ·  Posted (edited)

ok so im new to arrays and im using one to make a patch list for my online game and well heres my code

#include <ButtonConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
;==> File.au3 For The Array To Work, Rest For Gui And Buttons
 
 global $main ;==> Gui
 global $Input0, $Input0a ;==> Input Button and Read
 Global $space, $space20 ;==> Fillers For The List
 global $hour, $min, $simi ;==> For The Setup For Time
 global $string ;==> The Final String
 global $szDrive, $szDir, $szFName, $szExt ;==> Spliting The Array
 global $day, $month, $year, $autodate ;==> For The Setup For Date
 global $sizelen, $size, $size2, $sizefix ;==> For Size And Size Calulating
 _Main()


Func _Main()
$Main = GUICreate("Patcher List Writer", 400, 100) ;==> Create Gui
 $space = " ";==> Filler Size 1 
 $space20 = "                    " ;==> Filler Size 20 "Max"
 
 $simi = ":" ;==> Date Spliter
$hour = @hour ;==> Date Hour
$min = @min ;==> Date Min
 
 $year = @YEAR;==> Year
 $month = @MON;==> Month
 $day = @MDAY;==> Day
 
                if $hour = "1" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 1
                    $hour = "01"
                endif 
                if $hour = "2" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 2
                    $hour = "02"
                endif 
                if $hour = "3" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 3
                    $hour = "03"
                endif 
                if $hour = "4" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 4
                    $hour = "04"
                endif 
                if $hour = "5" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 5
                    $hour = "05"
                endif 
                if $hour = "6" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 6
                    $hour = "06"
                endif 
                if $hour = "7" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 7
                    $hour = "07"
                endif 
                if $hour = "8" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 8
                    $hour = "08"
                endif 
                if $hour = "9" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 9
                    $hour = "09"
                endif 
 
$autodate = $Year & "-" & $Month & "-" & $day ;==>  Complie The Date To The Format Needed
    GUICtrlCreateLabel("Date", 10, 20, 150, 20) ;==> Create Date Label
    GUICtrlCreateLabel("EG: 2009-05-27", 10, 50, 150, 20);==>  Create Eg Label

    $Input0 = GUICtrlCreateInput($autodate , 50, 15, 280, 20);==> Create Input Box On GUI
    $hinput = GUICtrlCreateButton("Input", 100, 40, 90, 30);==>  Create Input Box Name
     
GUISetState() ;==> Call State

        While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $hinput ;==> Clicked Input Button
                GUISetState(@SW_DISABLE) ;==>  So U Cant Over Lap The Array
                $Input0a = GUICtrlRead($Input0) ;==> Reads Input0 To Get The Date
                $array = _FileListToArray(@ScriptDir, "*", 1) ;==>  Gets File List
                $sizelen = StringLen($size) ;==> ok i was able to find the string length command
                $size2 = $sizelen - 20  ;==> but i still need to get the size for each file the array finds XD


                For $i = 1 to $array[0]
                    $TestPath = _PathSplit($array[$i], $szDrive, $szDir, $szFName, $szExt)  ;==> Splits The Filename And Extentions From The Rest
                    $string &= $input0a & $space & $space & $hour & $Simi & $min & $space20 & $sizefix & $TestPath[3] & $TestPath[4] & @CRLF   ;==> Complies The String
                Next
                run ("notepad.exe")  ;==>  Opens Notepad
                sleep (1000)  ;==>  My Time Delay For My Notepad Because The Title Is Different
                send ($string) ;==> Sends the string values to notepad
                GUISetState(@SW_ENABLE)  ;==> Once Writen Enable The GUI Agian
                exit ;==> then exit the gui
            Case $msg = $GUI_EVENT_CLOSE  ;==> if u click the X close the gui
                exit
                
        EndSelect        ;==>  ends case look   
        WEnd            
EndFunc ;==> _main

what it does is grab all file names + extensions and send them to a note pad at the moment but i want to get able to get the file size preferable byte XD other wise the patcher will loop.

Example:

2009-05-27 <Date

Gap Of 2 Spaces

21:52 < Time

Gap Of 20 Spaces between Time and file name to be made to length by counting the file size. (Eg If Size = 5 then spaces = 15 etc.)

Size <Size in Bytes

Gap Of 2 Spaces

Patch List.au3 <Name

i am working on the auto grab year and month.

last thing i need is just to get the filesize in a byte lenght so if anyone can give me insight i will hug ya XD

Thanks

Edit : Added New Code + Info Lines

Edited by Targus

Share this post


Link to post
Share on other sites



lol ok but how do i use this in this script XD im clueless ~.~

the main thing i need is the file size

so where should i put this

Local $iSize = FileGetSize(@ScriptFullPath)

so that it gets every file size that the array finds.

also i have done this to calculate the size values length

$sizelen = StringLen($size) ;==> ok i was able to find the string length command

$size2 = $sizelen - 20 ;==> but i still need to get the size for each file the array finds XD

then i do a nested if to set the $space2 lenght from 1-19 since a file must return atleast 1 number and i doubt i wil be using a 20 number length byte size file.

Share this post


Link to post
Share on other sites

For $i = 1 to $array[0]
     $iSize = FileGetSize($array[$i])
     $TestPath = _PathSplit($array[$i], $szDrive, $szDir, $szFName, $szExt)
      $string &= $input0a & $space & $space & $hour & $Simi & $min & $space20 & $sizefix & $TestPath[3] & $TestPath[4] & @CRLF   ;==> Complies The String
Next

Then use StringFormat() or your preferred method to nicely align and pad the file size in the string.

By the way, you don't need to use Send() to send to notepad, just create a file and write to it using FileWrite(), FileOpen().

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

XD thanks man im now gonna incorporate ur idea of filewrite.

thanks for all ur help.

EDIT: Fixed i am now able to make them all .gz XD

#include <ButtonConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
;==> File.au3 For The Array To Work, Rest For Gui And Buttons
 
 global $main ;==> Gui
 global $Input0, $Input0a ;==> Input Button and Read
 Global $space, $space20, $spaceal ;==> Fillers For The List
 global $hour, $min, $simi ;==> For The Setup For Time
 global $string ;==> The Final String
 global $szDrive, $szDir, $szFName, $szExt ;==> Spliting The Array
 global $day, $month, $year, $autodate ;==> For The Setup For Date
 global $sizelen, $size, $size2, $sizefix ;==> For Size And Size Calulating
 _Main()


Func _Main()
$Main = GUICreate("Patcher List Writer", 400, 100) ;==> Create Gui
 $space = " ";==> Filler Size 1 
 $space20 = "          " ;==> Filler Size 20 "Max"
 
 $simi = ":" ;==> Date Spliter
$hour = @hour ;==> Date Hour
$min = @min ;==> Date Min
 
 $year = @YEAR;==> Year
 $month = @MON;==> Month
 $day = @MDAY;==> Day
 
                if $hour = "1" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 1
                    $hour = "01"
                endif 
                if $hour = "2" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 2
                    $hour = "02"
                endif 
                if $hour = "3" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 3
                    $hour = "03"
                endif 
                if $hour = "4" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 4
                    $hour = "04"
                endif 
                if $hour = "5" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 5
                    $hour = "05"
                endif 
                if $hour = "6" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 6
                    $hour = "06"
                endif 
                if $hour = "7" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 7
                    $hour = "07"
                endif 
                if $hour = "8" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 8
                    $hour = "08"
                endif 
                if $hour = "9" Then ;==> Makes Sure Hour Has A 0 Before It If It Is 9
                    $hour = "09"
                endif 
 
$autodate = $Year & "-" & $Month & "-" & $day ;==>  Complie The Date To The Format Needed
    GUICtrlCreateLabel("Date", 10, 20, 150, 20) ;==> Create Date Label
    GUICtrlCreateLabel("EG: 2009-05-27", 10, 50, 150, 20);==>  Create Eg Label

    $Input0 = GUICtrlCreateInput($autodate , 50, 15, 280, 20);==> Create Input Box On GUI
    $hinput = GUICtrlCreateButton("Input", 100, 40, 90, 30);==>  Create Input Box Name
     
GUISetState() ;==> Call State

        While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $hinput ;==> Clicked Input Button
                GUISetState(@SW_DISABLE) ;==>  So U Cant Over Lap The Array
                $Input0a = GUICtrlRead($Input0) ;==> Reads Input0 To Get The Date
                $array = _FileListToArray(@ScriptDir, "*", 1) ;==>  Gets File List

                For $i = 1 to $array[0]
                    $Size = FileGetSize($array[$i])
                    $sizelen = StringLen($size) ;==> ok i was able to find the string length command
                    $size2 = $sizelen - "20"    ;==> but i still need to get the size for each file the array finds XD
                    $TestPath = _PathSplit($array[$i], $szDrive, $szDir, $szFName, $szExt)  ;==> Splits The Filename And Extentions From The Rest
                    if $size2 = "-1" Then
                        $spaceal = " "
                    endif 
                    ;==> 19 Byte Size
                    if $size2 = "-2" Then
                        $spaceal = "  "
                    endif 
                    ;==> 18 Byte Size
                    
                    if $size2 = "-3" Then
                        $spaceal = "   "
                    endif 
                    ;==> 17 Byte Size
                    
                    if $size2 = "-4" Then
                        $spaceal = "    "
                    endif 
                    ;==> 16 Byte Size
                    if $size2 = "-5" Then
                        $spaceal = "     "
                    endif 
                    ;==> 15 Byte Size
                    
                    if $size2 = "-3" Then
                        $spaceal = "      "
                    endif 
                    ;==> 14 Byte Size
                    
                    if $size2 = "-7" Then
                        $spaceal = "       "
                    endif 
                    ;==> 13 Byte Size
                    
                    if $size2 = "-8" Then
                        $spaceal = "        "
                    endif 
                    ;==> 12 Byte Size
                    if $size2 = "-9" Then
                        $spaceal = "         "
                    endif 
                    ;==> 11 Byte Size
                    
                    if $size2 = "-10" Then
                        $spaceal = "          "
                    endif 
                    ;==> 10 Byte Size
                    
                    if $size2 = "-11" Then
                        $spaceal = "           "
                    endif 
                    ;==> 9 Byte Size
                    
                    if $size2 = "-12" Then
                        $spaceal = "            "
                    endif 
                    ;==> 8Byte Size
                    
                    if $size2 = "-13" Then
                        $spaceal = "             "
                    endif 
                    ;==> 7 Byte Size
                    
                    if $size2 = "-14" Then
                        $spaceal = "              "
                    endif 
                    ;==> 6 Byte Size
                    
                    if $size2 = "-15" Then
                        $spaceal = "               "
                    endif 
                    ;==> 5 Byte Size
                    
                    if $size2 = "-16" Then
                        $spaceal = "                "
                    endif 
                    ;==> 4 Byte Size
                    
                    if $size2 = "-17" Then
                        $spaceal = "                 "
                    endif 
                    ;==> 3 Byte Size
                    
                    if $size2 = "-18" Then
                        $spaceal = "                  "
                    endif 
                    ;==> 2 Byte Size
                    
                    if $size2 = "-18" Then
                        $spaceal = "                   "
                    endif 
                    ;==> 1 Byte Size
                    
                    if $size2 = "-19" Then
                        $spaceal = "                    "
                    endif 
                    ;==> 1 Byte Size
                    $string &= $input0a & $space & $space & $hour & $Simi & $min & $spaceal & $size & $space & $space & $TestPath[3] & $TestPath[4] & @CRLF   ;==> Complies The String
                    
                Next
                run ("notepad.exe")  ;==>  Opens Notepad
                sleep (1000)  ;==>  My Time Delay For My Notepad Because The Title Is Different
                send ($string) ;==> Sends the string values to notepad
                GUISetState(@SW_ENABLE)  ;==> Once Writen Enable The GUI Agian
                exit ;==> then exit the gui
            Case $msg = $GUI_EVENT_CLOSE  ;==> if u click the X close the gui
                exit
                
        EndSelect        ;==>  ends case look   
        WEnd            
EndFunc ;==> _main
Edited by Targus

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