Skip to main content

[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.

[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.
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.

[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.
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.

[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.
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.


[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.
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.