Jump to content

File size question


Recommended Posts

Hi all,

I am working on a script and am stuck (again) in calculating the size of all files in a folder.

Basically, what I want to do is to copy any file that is less than 5k in size to another folder

I am able to loop through the files but it return zero for the file size. Here is the code I have so far. Any help will be appreciated.

$path = @ScriptDir & '\result\'
$search = FileFindFirstFile($path & '*.*')
while 1
$file = FileFindNextFile($search)
if @error then ExitLoop
$size = FileGetSize($file)
ConsoleWrite('File ' & $file & 'is '  & $size & @cr)
WEnd
Edited by Santana

Just another special date with a different challenge

Link to comment
Share on other sites

@ Authenticity

you're right, I tested only in the current dir

$path = @ScriptDir & "\result\"
$search = FileFindFirstFile($path & "*.*")
$size = 0

while 1
    $file = FileFindNextFile($search)
    if @error then ExitLoop
    $size = $size + FileGetSize($path & $file)
WEnd

MsgBox(4096, "Total size = ", $size)
FileClose($search)

Note that FileFindFirstFile does not recurse folders

Edited by Inverted
Link to comment
Share on other sites

Thanks Inverted. It works great. Now, I thought the easiest part was to write

$kilo = $size/1024 to get the size in k but the size doesnt match the file size when I right click and hit property

any hint??

thanks again

Edited by Santana

Just another special date with a different challenge

Link to comment
Share on other sites

The bytes are correct. (Unless you have other folder inside \result)

Or is the discrepancy after converting to kbs ?

Also, I hope you're not confusing "size" and "size on disk". Size on disk is bigger because of the way the filesystem works (depends on the allocation unit size)

EDIT: I forgot you want to check each file, I thought we were adding up the sizes, lol. Anyway, you can go on your own, it's not complex to compare each file's size to 5*1024

Edited by Inverted
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...