Highlighted
Absent Member.
Absent Member.
189 views

[archive] Determining free disk space in Windows

[Migrated content. Thread originally posted on 18 November 2005]

I know this should be simple, but is there any functions that will return current disk info. I know I can do a system call and re-direct the output of a dir command, etc, but I was looking for something that could be called within the cobol code directly.

I've searched the online manuals and haven't been able to find anything.
0 Likes
4 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Determining free disk space in Windows

Search msdn for GetDiskFreeSpaceEX (to be compatible with huge disks). Note though ULARGE_INTEGER is 8 byte, e.g. you should pass address to 8 byte memory. For instance: PIC X(8) COMP-N.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Determining free disk space in Windows

I found that reference in the SDK guide. However I can't seem to get it to work. I know we went over this in class when I was there last January, but I've been going through a move and I'm not able to find my notes.
Here is what I have so far.

01 local-disk pic x(32).
01 free-bytes-c pic x(8) comp-n.
01 Total-Bytes pic x(8) comp-n.
01 Free-Bytes pic x(8) comp-n.

move low-values to local-disk
SET ENVIRONMENT "DLL_CONVENTION" TO "1"
call "GetDiskFreeSpaceEx" using by reference local-disk,
by reference free-bytes-c,
by reference Total-Bytes,
by reference Free-Bytes.

The problem I have is that when the call command is issued, the program just simply goes away. There is no message or error of any kind. I seem to recall that there was more to than this, but I can't remember. I will keep searching to see if I can find my notes, but if you could help me along with this that would be appreciated as well.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Determining free disk space in Windows

You have not loaded the dll, nor have you set what drive.


       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"
           STOP    RUN.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Determining free disk space in Windows

Thanks,
The part I was forgetting was the call to Kernel32.dll. The SDK doc says you can pass a null for the directory specification and it will use the root of the current drive.

lpDirectoryName
[in] Pointer to a null-terminated string that specifies a directory on the disk of interest. If this parameter is NULL, the function uses the root of the current disk. If this parameter is a UNC name, it must include a trailing backslash (for example, \\MyServer\MyShare\).
Note that this parameter does not have to specify the root directory on a disk. The function accepts any directory on the disk.

I really appreciate you help on this.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.