Santana Posted June 10, 2009 Posted June 10, 2009 (edited) 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 June 10, 2009 by Santana Just another special date with a different challenge
Inverted Posted June 10, 2009 Posted June 10, 2009 (edited) $search = FileFindFirstFile(@ScriptDir & '\result\*.*') $size = 0 while 1 $file = FileFindNextFile($search) if @error then ExitLoop $size = $size + FileGetSize($file) WEnd MsgBox(4096, "Total size = ", $size) FileClose($search) Edited June 10, 2009 by Inverted
Authenticity Posted June 10, 2009 Posted June 10, 2009 The return value is the file name only, without the path. You'll need to concatenate the path also, or change the current working directory. If the current directory is the directory you're searching then it should work without any problem.
Inverted Posted June 10, 2009 Posted June 10, 2009 (edited) @ 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 June 10, 2009 by Inverted
Santana Posted June 10, 2009 Author Posted June 10, 2009 (edited) 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 June 10, 2009 by Santana Just another special date with a different challenge
Inverted Posted June 10, 2009 Posted June 10, 2009 (edited) 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 June 10, 2009 by Inverted
Santana Posted June 10, 2009 Author Posted June 10, 2009 [RESOLVED] Thanks so much Inverted. got it working now. Just another special date with a different challenge
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now