replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - WinAPI function of free disk space left
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WinAPI function of free disk space left

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
DanRRight



Joined: 10 Mar 2008
Posts: 2911
Location: South Pole, Antarctica

PostPosted: Sun Jul 21, 2024 11:26 pm    Post subject: WinAPI function of free disk space left Reply with quote

Is there such function? Good would be to create with Clearwin such a reminder that will warn you that the hard drives free space limit is approaching.

Workarounds like "Dir >file" and then looking into the file is too slow if the directory has thousands of files

Or similar function for Linux?
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Mon Jul 22, 2024 1:45 am    Post subject: Reply with quote

To speed up you could try something like:

"Dir zz.* >file"

( although I am not familiar with correct syntax to select the appropriate drive and directory )
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8184
Location: Salford, UK

PostPosted: Mon Jul 22, 2024 7:44 am    Post subject: Reply with quote

If you right click on a hard drive in File Explorer then it gives you the used and free space immediately. The same is true for the Settings (System > Storage > Disks & volumes).

This suggests that the hard drive values are kept somewhere in the registry but I don't know where to find them.

If you right click on a folder in File Explorer then it starts to calculate the sizes and this can take a while. This implies that the sizes are accessed and summed dynamically.

The FTN95 subroutines FILES@ or FILES8@ (for example) could be used to get file sizes for summing but how long would this take to compute?

At a lower level (in C rather than Fortran) one could call FindFirstFile and FindNextFile (for example) recursively and sum the sizes from the returned data structures. Again this might not be fast enough for your purposes.
Back to top
View user's profile Send private message AIM Address
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Mon Jul 22, 2024 11:19 am    Post subject: Reply with quote

Paul,

"If you right click on a hard drive in File Explorer then it gives you the used and free space immediately"

This would be a statistic readily obtained from the file availability table statistics of the selected logical disk.
= ( total_sectors - sectors_allocated ) * sector_size_bytes

Is there any WINAPI that provides these values.

( there is for memory availability
!ftn95 stdcall GlobalMemoryStatusEx 'GlobalMemoryStatusEx'(REF):logical
! logical, external :: GlobalMemoryStatusEx )

FILES@ does not appear to have access to total disk size so might not help.
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2402
Location: Yateley, Hants, UK

PostPosted: Mon Jul 22, 2024 1:54 pm    Post subject: Reply with quote

Well, Dan, If you are afraid that you are approaching your disk limit with the general run of things in your work, you can keep a check by interrogating 'Properties' for any disk in the File Explorer. Provided you do this on a regular basis, it gives you enough time to go out and buy a larger disk, and install it in your PC. The costs involved, and time taken, are a fraction of the inconvenience of running up against a limit and causing a crash.

If it is a matter of a temporary file storage issue, then keep a drive specifically for those temporary files. The shop I use has 5Tb SSDs and spinning disks, the latter only 25% of the cost of the former, and even those are priced at a fraction of a day's consulting charge-out rate.

Eddie
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8184
Location: Salford, UK

PostPosted: Mon Jul 22, 2024 3:28 pm    Post subject: Reply with quote

Here is some code to try...

Code:
program main
c_external GetDiskSpaceInformation 'GetDiskSpaceInformationA'(INSTRING,REF):LOGICAL
type DISK_SPACE_INFORMATION
  sequence
  integer(4) ActualTotalAllocationUnits;
  integer(4) ActualAvailableAllocationUnits;
  integer(4) ActualPoolUnavailableAllocationUnits;
  integer(4) CallerTotalAllocationUnits;
  integer(4) CallerAvailableAllocationUnits;
  integer(4) CallerPoolUnavailableAllocationUnits;
  integer(4) UsedAllocationUnits;
  integer(4) TotalReservedAllocationUnits;
  integer(4) VolumeStorageReserveAllocationUnits;
  integer(4) AvailableCommittedAllocationUnits;
  integer(4) PoolAvailableAllocationUnits;
  integer(3) SectorsPerAllocationUnit;
  integer(3) BytesPerSector;
end type
type(DISK_SPACE_INFORMATION)::diskSpaceInfo
logical res
diskSpaceInfo = DISK_SPACE_INFORMATION(0,0,0,0,0,0,0,0,0,0,0,0,0)
res = GetDiskSpaceInformation("C:\", diskSpaceInfo)
print*, diskSpaceInfo
end program


res returns FALSE (which is wrong) but the data structure is filled.
Back to top
View user's profile Send private message AIM Address
DanRRight



Joined: 10 Mar 2008
Posts: 2911
Location: South Pole, Antarctica

PostPosted: Mon Jul 22, 2024 7:02 pm    Post subject: Reply with quote

Thanks all for suggestions. Why i need this subroutine is that no matter how many other places will tell you about the size what is left (and each of 10-20 open Total Commanders, or Double Commanders on top clearly write the number of free space left ) you always will miss this ball. The idea is to make warning when it happen, flash the light, generate sound, to wake you up and/or just pause the run before the crash happen. In 4+ decades i run the codes which always generate a lot of large files i probably lost a year just on that "disk full" crashes because the night run was not complete or continuation file was damaged pushing me to run again.

Paul,
This is what i was looking for, many thanks.

I got some problem though which is not related to the code, may be you can suggest where to look for the source: code works on true Windows computer but complains on emulated Windows one (in Linux) by unknown reason. I never had any problems like that before, all Windows stuff worked like i am in true Windows. The error is : Call to missing routine_GetDiskSpaceInformationA. Is it possible that my emulator uses probably the oldest version of WIndows 10 ? I remember 5 or more years ago in Windows were some changes of this sort
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8184
Location: Salford, UK

PostPosted: Tue Jul 23, 2024 7:11 am    Post subject: Reply with quote

Dan

This function requires Windows 10 or 11.

https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskspaceinformationw

You could try using the UNICODE form: GetDiskSpaceInformationW but you would need to change the first argument as well.
Back to top
View user's profile Send private message AIM Address
DanRRight



Joined: 10 Mar 2008
Posts: 2911
Location: South Pole, Antarctica

PostPosted: Wed Jul 24, 2024 11:20 pm    Post subject: Reply with quote

Paul, thanks, unfortunately looks like the Windows used by my relatively old version of WINE 6.0.3 is too old too. Will experiment with newer WINE and newer Windows later.

/* By the way WINE is great emulator of Windows for Linux (literally ideal one, much more convenient and stable than for example VirtualBox ) but is very picky at installation time. I hope Android and Chrome will teach entire Linux community how desktop Linux has to be implemented (all 1000 installations/uninstalls by billions people were done in one click and no single problem were with system updates in decade)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group