Sign in to follow this  
Followers 0
blindwig

How to get the allocated file size?

29 posts in this topic

Does AutoIt have a funciton to get the allocated file size?

I know that FileGetSize will return the actual size of the file, but say I have a 5k file on a filesystem using 4k blocks. Obviously the file has 8k allocated for it. Is there a built-in function to tell me this?

Share this post


Link to post
Share on other sites



Does AutoIt have a funciton to get the allocated file size?

I know that FileGetSize will return the actual size of the file, but say I have a 5k file on a filesystem using 4k blocks.  Obviously the file has 8k allocated for it.  Is there a built-in function to tell me this?

<{POST_SNAPBACK}>

no that I know about :">

Share this post


Link to post
Share on other sites

Is that hard to do in C++? I mean, would it be easy for the devs to add a built-in function (or a flag to the original FileGetSize() function) or should I figure out a way to do it through a DLL call?

Share this post


Link to post
Share on other sites

Is that hard to do in C++?  I mean, would it be easy for the devs to add a built-in function (or a flag to the original FileGetSize() function) or should I figure out a way to do it through a DLL call?

I doubt there is a user mode API call for this in Windows. However, I'm happy if you find one.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

I doubt there is a user mode API call for this in Windows. However, I'm happy if you find one.

Cheers

Kurt

<{POST_SNAPBACK}>

I took a look and I didn't spot a function that jumped out sand said, "Hey, look-it-me, I'm the one you want". I would first try Google and see if there is anything about it there. If not, then the best I can think of is to find out the block-size for the drive the file is located on and then find the next multiple of the drive size that is larger than the current file size. Do all that programmatically, of course. I'm afraid I don't know of any API function off the top of my head that gives the partition block size, though.

Share this post


Link to post
Share on other sites

I assume that it's built into windows somewhere, because if you view a file's properties in Windows Explorer there is a text that says "Size on Disk". on my system I'm noticing that it's always a multiple of 4K, which makes sense since my HD is formatted NTFS with 4K blocks.

And I could have sworn that DIR used to have an undocumented switch to return allocated size instead of actual size, but I can't find any info on it.

Hmm... OK, so does anyone know how to determine the block-size of a file system from a given file name?

Share this post


Link to post
Share on other sites

current file size.  Do all that programmatically, of course.  I'm afraid I don't know of any API function off the top of my head that gives the partition block size, though.

<{POST_SNAPBACK}>

Not an API call, but WMI Class Win32_Volume can do it (Parameter: Blocksize).

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Not an API call, but WMI Class Win32_Volume can do it (Parameter: Blocksize).

Cheers

Kurt

<{POST_SNAPBACK}>

Windows XP and earlier: This class is not available

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Windows XP and earlier:  This class is not available

<{POST_SNAPBACK}>

Ups.. you're right, requires Windows Server 2003. Sorry, then I don't know a way how to do it.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

What is I have found, try this code (need beta of course):

$pGDFS = DllStructCreate("dword;dword;dword;dword")

$ret = DllCall("kernel32.dll","int","GetDiskFreeSpace",_
                    "str", "C:\",_
                    "ptr",DllStructGetPtr($pGDFS,1),_
                    "ptr",DllStructGetPtr($pGDFS,2),_
                    "ptr",DllStructGetPtr($pGDFS,3),_
                    "ptr",DllStructGetPtr($pGDFS,4))

$res = DllStructGetData($pGDFS, 1) * DllStructGetData($pGDFS, 2)
DllStructDelete($pGDFS)
MsgBox (0, "Cluster Size", $res)

Tested only under XP, but this should works on earlier versions.

Share this post


Link to post
Share on other sites

Sweet - I tried it here on XP pro and it works - even for network drives!

Thanks!

Share this post


Link to post
Share on other sites

something like this ?

Func _FileGetRealSize($s_path)
    
If Not FileExists($s_path) Then
    SetError(1)
    Return 0
EndIf
    
Local $s_drive = StringLeft($s_path, 3)
    
If StringLeft($s_path, 1) = '.' Then $s_drive = StringLeft(@ScriptDir, 3)
If StringLeft($s_path, 2) = '\\' Then $s_drive = StringLeft($s_path, StringInStr($s_path, '\', 0, 3)
    
ConsoleWrite($s_drive & @LF)
    
$v_struct = DllStructCreate("dword;dword;dword;dword")

$ai_ret = DllCall("kernel32.dll","int","GetDiskFreeSpace",_
                    "str", $s_drive,_
                    "ptr",DllStructGetPtr($v_struct,1),_
                    "ptr",DllStructGetPtr($v_struct,2),_
                    "ptr",DllStructGetPtr($v_struct,3),_
                    "ptr",DllStructGetPtr($v_struct,4))

$i_res = DllStructGetData($v_struct, 1) * DllStructGetData($v_struct, 2)
DllStructDelete($v_struct)

$i_size = FileGetSize($s_path)
$i_size = Ceiling($i_size/$i_res)*$i_res

Return $i_size

EndFunc

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

Sweet - I tried it here on XP pro and it works - even for network drives!

Thanks!

Out of morbid curiousity is that a real gonk or an clip-art gonk?

Gonks are are biggest unheard anti-desktop rollout agent of the 21st century :)

Share this post


Link to post
Share on other sites

Out of morbid curiousity is that a real gonk or an clip-art gonk?

uhhh... Gonk? Do you mean my Avatar? It's a picture of a stress ball I have on my desk at work. My girlfriend gave it to me last Christmas and it's already pretty worn - you can see the tounge is starting to peel off and the eyes are cracking. I took it on my cell phone and blue-toothed it to my laptop (my main computer at work) and scaled it and uploaded it here.

Gonks are are biggest unheard anti-desktop rollout agent of the 21st century :)

uhhh... you really lost me there. Please rephrase?

Share this post


Link to post
Share on other sites

something like this ?

Yeah, looks good.

There was a missing ) on line 11, and you need to include math.au3 and use _Ceil(), but other than that it works.

Oh, and you need to change the StringInStr line to find the 4th occurance of '\' instead of the 3rd, because '\\127.0.0.1\' is not a drive, but '\\127.0.0.1\c-drive\' is.

And I didn't realize this, but _Ceil() returns 1 when given a 0, so this even works on 0k files (which should have 1 cluster allocated to them)

Cool.

Share this post


Link to post
Share on other sites

And I didn't realize this, but _Ceil() returns 1 when given a 0, so this even works on 0k files (which should have 1 cluster allocated to them)

Cool.

On (at least NTFS), a 0-byte file is only stored in the MFT. There is no actual hard disk space used and the file will be 0 bytes until the first character is added, then it will obtain disk space to be stored.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

uhhh...  Gonk?  Do you mean my Avatar?...

<{POST_SNAPBACK}>

Not to speak for Jon, but I googled "gonk" when I saw his post last night.

Toward the bottom of this page are some pictures of what someone else calls a gonk: http://www.twingo.net/twungi.html

Perhaps the little character added to what appears to be an album or CD cover is also a gonk: http://www.geocities.com/philippesmash/gonkspic.jpg

It must mean something on the other side of the pond.....

edit typo

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

So how many 0-byte files can you fit on a hard drive before it fills up? :)

<{POST_SNAPBACK}>

Well, technically speaking, they do take up something because at least the name/location is stored in the Master File Table. So assuming you wished to take the time, I suppose it's theoretically possible that you could create enough 0 byte files to fill the MFT causing it to expand and expand until it used up the entire hard drive. However, I would suspect that it is not possible for the MFT to do that, there is surely a cap on its growth size. Also, I would argue that the 0 byte files are not what is filling the hard drive up but rather the information being used to record their existence. So I would say that you could fit as many files as you had: BytesFreeSpace / SizeOfFileEntryInMFT = NumberOfZeroByteFiles.

I'm intrigued by this...

Share this post


Link to post
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
Sign in to follow this  
Followers 0