Skip to main content

[archive] Query Available Space on disk

  • March 24, 2006
  • 10 replies
  • 0 views

[Migrated content. Thread originally posted on 23 March 2006]

Hi there.

Is there a way for me to query the available space on my disk drive?

Marelize

10 replies

[Migrated content. Thread originally posted on 23 March 2006]

Hi there.

Is there a way for me to query the available space on my disk drive?

Marelize
Hello

There is not a direct way. You must use an API call.

You can use function like "GetFreeDiskSpace" in KERNEL32.dll I presume.

Take a look at MSDN from Microsoft for usage and parameters.

Good luck.

[Migrated content. Thread originally posted on 23 March 2006]

Hi there.

Is there a way for me to query the available space on my disk drive?

Marelize
Hello

There is not a direct way. You must use an API call.

You can use function like "GetFreeDiskSpace" in KERNEL32.dll I presume.

Take a look at MSDN from Microsoft for usage and parameters.

Good luck.

[Migrated content. Thread originally posted on 23 March 2006]

Hi there.

Is there a way for me to query the available space on my disk drive?

Marelize
Hello

There is not a direct way. You must use an API call.

You can use function like "GetFreeDiskSpace" in KERNEL32.dll I presume.

Take a look at MSDN from Microsoft for usage and parameters.

Good luck.

[Migrated content. Thread originally posted on 23 March 2006]

Hi there.

Is there a way for me to query the available space on my disk drive?

Marelize
Thanx

Will try that for windows. I forgot to mention that we're running thin-client on a unix-box. Any suggestions?

Marelize

[Migrated content. Thread originally posted on 23 March 2006]

Hi there.

Is there a way for me to query the available space on my disk drive?

Marelize
You could do a call to C$SYSTEM with the UNIX command "df -v>df.txt"

This would create a text file called "df.txt" which you could then open as a line sequential file from your program. The file would contain information like the following:

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda3 17132844 3931856 12330668 25% /
/dev/hda1 101089 25129 70741 27% /boot
/dev/hdb1 76944512 4876256 68159644 7% /export
none 1032320 0 1032320 0% /dev/shm

The forum software has compressed a lot of the spaces betweent he columns but hopefully you can see the output you get from the "df -v" command.

The "df -v" command is normally available on most UNIX flavours but the output normally differs slightly between them.

[Migrated content. Thread originally posted on 23 March 2006]

Hi there.

Is there a way for me to query the available space on my disk drive?

Marelize
Thanx for the help.

Will try it.

[Migrated content. Thread originally posted on 23 March 2006]

Hi there.

Is there a way for me to query the available space on my disk drive?

Marelize
Thanx for the help.

Will try it.

[Migrated content. Thread originally posted on 23 March 2006]

Hi there.

Is there a way for me to query the available space on my disk drive?

Marelize
Thanx for the help.

Will try it.

[Migrated content. Thread originally posted on 23 March 2006]

Hi there.

Is there a way for me to query the available space on my disk drive?

Marelize
Alternatively you can create an INPUT file with path "-P df -v" and READ the output of the command directly. This would cut out the middle step of having to save the output to a file and then open the file.

If you are really adventurous, you could add a C routine to your runtime which calls the 'statfs' system routine (see 'man 2 statfs') to return the 'statfs' struct, which contains the fields 'f_bfree' (free blocks) and 'f_bsize' (file system block size). You pass it the path that you want to get stats for.

Hope this helps.

BTW, if you do happen to implement a C routine, I'd be interested in looking at it as I've only researched this, not actually implemented it. :)

[Migrated content. Thread originally posted on 23 March 2006]

Hi there.

Is there a way for me to query the available space on my disk drive?

Marelize
IDENTIFICATION DIVISION.
PROGRAM-ID. TEMPLATE.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
WORKING-STORAGE SECTION.

77 CNTL-FONT USAGE HANDLE OF FONT SMALL-FONT.
77 KEY-STATUS IS SPECIAL-NAMES
CRT STATUS PIC 9(4) VALUE 0.
88 EXIT-PRESSED VALUE 27.
77 FreeBytesToUser PIC X(8) COMP-N.
77 TotalDiskCapacity PIC X(8) COMP-N.
77 TotalFreeBytes PIC X(8) COMP-N.
77 LocalDisk PIC X(32).
77 ZFreeBytesToUser
PIC Z(03),Z(03),Z(03),Z(03),Z(03),999.
77 ZTotalDiskCapacity
PIC Z(03),Z(03),Z(03),Z(03),Z(03),999.
77 ZTotalFreeBytes
PIC Z(03),Z(03),Z(03),Z(03),Z(03),999.
PROCEDURE DIVISION.
MAIN-LOGIC.

STRING "C:\\" LOW-VALUES DELIMITED BY SIZE
INTO LocalDisk.
SET ENVIRONMENT "DLL_CONVENTION" TO "1".
CALL "Kernel32.DLL".
CALL "GetDiskFreeSpaceExA" USING
BY REFERENCE LocalDisk
BY REFERENCE FreeBytesToUser
BY REFERENCE TotalDiskCapacity
BY REFERENCE TotalFreeBytes.
CANCEL "Kernel32.DLL".
DIVIDE FreeBytesToUser BY 1024
GIVING ZFreeBytesToUser.
DIVIDE TotalDiskCapacity BY 1024
GIVING ZTotalDiskCapacity.
DIVIDE TotalFreeBytes BY 1024
GIVING ZTotalFreeBytes.
DISPLAY MESSAGE BOX
"User available:" x"09" ZFreeBytesToUser " Kb"
x"0a"
"Disk capacity.:" x"09" ZTotalDiskCapacity " Kb"
x"0a"
"Total free....:" x"09" ZTotalFreeBytes " Kb"
TITLE "Space on C:"
x"0a"

Hope it'll help...