AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FileGetSize Bug

 
Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Sat Nov 28, 2009 3:27 pm    Post subject: FileGetSize Bug Reply with quote

Code:
FileGetSize, filesize, L:\Users\sfufoet\Desktop\Free Process Freezer-Appinn.com.7z, M
tooltip %filesize%
sleep 2000


The size of “Free Process Freezer-Appinn.com.7z” is 2.73MB
But,I run the codes, filesize=2
Sad
Back to top
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Sat Nov 28, 2009 4:31 pm    Post subject: Reply with quote

AHK Help File wrote:
OutputVar The name of the variable in which to store the retrieved size (rounded down to the nearest whole number).
I've wished for quite some time that it would not do this: FileGetSize & SetFormat.
Back to top
View user's profile Send private message Visit poster's website
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Sat Nov 28, 2009 5:28 pm    Post subject: Reply with quote

Try this:
Code:
FileGetSize(file,Units=""){
   static K:=1024,M:=1048576
   FileGetSize,size,%file%
   If Units
      size := size/%Units%
   Return Round(size)
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Sat Nov 28, 2009 5:58 pm    Post subject: Reply with quote

B is a valid unit, even though the documentation doesn't explicitly mention it.
Code:
FileGetSize(file,Units="B"){
   static B:=1,K:=1024,M:=1048576
   FileGetSize,size,%file%
   size//=%Units%
   Return size
}

Actually, in the old post I linked to above, I recommended using SetFormat to effect the returned size. I still think that makes the most sense.
Back to top
View user's profile Send private message Visit poster's website
nick



Joined: 24 Aug 2005
Posts: 549
Location: Berlin / Germany

PostPosted: Sun Nov 29, 2009 9:27 am    Post subject: Reply with quote

Another one:
Code:
FileGetSize(File, Units="") {
   ; Units: K = KB, M = MB
   ; optional immediately followed by the number of decimal places (1 - 9)
   Static K := 1024, M := 1048576
   RegExMatch(Units, "i)^(K|M)(\d?)", U)
   FileGetSize, Size, %File%
   Return  U1 ? Round(Size / %U1%, U2) : Size
}

_________________
nick Wink
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Nov 29, 2009 12:52 pm    Post subject: Reply with quote

THX!
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group