Jump to content

Recommended Posts

Posted

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
Posted

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?

  • Moderators
Posted (edited)

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.

Posted

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]

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
×
×
  • Create New...