AutoHotkey Community

It is currently May 27th, 2012, 2:56 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: FileGetSize Bug
PostPosted: November 28th, 2009, 4:27 pm 
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
:(


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2009, 5:31 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2009, 6:28 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
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:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2009, 6:58 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 29th, 2009, 10:27 am 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
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:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 29th, 2009, 1:52 pm 
THX!


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group