Jump to content
Sign in to follow this  
spac3m0nk3y

Filename and filesize in an array

Recommended Posts

spac3m0nk3y

I've got a function that puts filenames with a certain beginning ID in an array.

$ID = _GUICtrlListViewGetItemText($lstProviders,  -1, 1)
$NumFiles = _FileListToArrayEx($filePath, $ID & '*.doc')

This works fine, except I would also like to add the size of the file to the array, so I can display that in a listview. Is there a way I can do this?

I tried it this way, but it always shows zero filesize:

If IsArray($NumFiles) Then
  GUICtrlSetData($getLst, '');Empty the control $lstProviders

  For $i = 1 To $NumFiles[0]
    GUICtrlCreateListViewItem($NumFiles[$i] & Chr(124) & FileGetSize($NumFiles[$i]) & Chr(124), $getLst)
  Next
EndIf

Share this post


Link to post
Share on other sites
PsaltyDS

FileGetSize() needs a full path to the file. Are you by any chance giving it only the file name without the folder path?

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
spac3m0nk3y

FileGetSize() needs a full path to the file. Are you by any chance giving it only the file name without the folder path?

:P

Ugh, you were right, once I added the path, it showed the filesize, DUH!

Ok, now is there an algorithm that I can perform on the filesize to have it only show something like 60KB or 1.5MB or something like that, instead of the actual bytes?

Share this post


Link to post
Share on other sites
SmOke_N

FileGetSize(...) / 1024 = kb

(FileGetSize(...) / 1024) / 1024 = mb

Edit:

Added iteration... I'm sure you get the picture now.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Monamo

Ugh, you were right, once I added the path, it showed the filesize, DUH!

Ok, now is there an algorithm that I can perform on the filesize to have it only show something like 60KB or 1.5MB or something like that, instead of the actual bytes?

Here's what I typically use when working with the "bytes-only" return:

Const $1GB = 1024 * 1024 * 1024
Const $1MB = 1024 * 1024
Const $1KB = 1024

$targetFile = "C:\pagefile.sys" 

$SpaceCalc = FileGetSize($targetFile)
Select
    Case $SpaceCalc > $1GB
        $sApproximateSpace = $SpaceCalc / $1GB
        $sComparison = "GB" 
    Case $SpaceCalc > $1MB And $SpaceCalc < $1GB
        $sApproximateSpace = $SpaceCalc / $1MB
        $sComparison = "MB" 
    Case $SpaceCalc >= "0"  And $SpaceCalc < $1MB
        $sApproximateSpace = $SpaceCalc / $1KB
        $sComparison = "KB" 
    Case Else
EndSelect
If StringInStr($sApproximateSpace, ".") Then
    $sApproximateSpace = StringTrimRight($sApproximateSpace, StringLen($sApproximateSpace) - StringInStr($sApproximateSpace, ".") - 1)
Else
EndIf
MsgBox(64, "Approximate (rounded) file size", $sApproximateSpace & " " & $sComparison)

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

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  

×