Microsoft KB Archive/64897

How to Remove a Directory Using a Protected Mode COBOL Program

PSS ID Number: Q64897 Article last modified on 11-19-1990

3.00 3.00a 4.00 OS/2

Summary: A protected mode COBOL version 3.00, 3.00a, or 4.00 program can remove a disk directory by calling the OS/2 API function DosRmDir. Below is a sample program illustrating how this is done. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS OS/2 and to Microsoft COBOL Professional Development System (PDS) version 4.00 for MS OS/2.

More Information: OS/2 API functions can be called directly from COBOL 3.00, 3.00a, and 4.00 by prefixing the name of the function with a double-underscore (__) and linking with the DOSCALLS.LIB library. DosRmDir takes the following parameters:

Note that a DWORD in COBOL has a picture clause of 9(8) COMP-5, and an ASCIIZ is a PIC X data item terminated with a null (ASCII 0). Furthermore, data items prefixed with PTR must be passed BY REFERENCE; otherwise, they are passed BY VALUE. The parameters must also be passed in the reverse order in the CALL statement because OS/2 API functions use a calling convention that is the reverse of COBOL’s. For more information on calling OS/2 API functions from COBOL 3.00 and 3.00a, see the file OS2API.DOC included with version 3.00a. For more information on DosRmDir, see page 556 of “Advanced OS/2 Programming” by Ray Duncan (Microsoft Press, 1989). The following sample program (REMOVDIR.CBL) prompts you for a directory name and removes it. To compile and link the program, enter the following at the OS/2 command prompt: pcobol removdir; link /nop removdir,,,pcobol doscalls; The compile and link lines for COBOL PDS 4.00 are as follows: cobol removdir; link removdir,,,coblib os2;

REMOVDIR.CBL
$SET ANS85 OSVS IDENTIFICATION DIVISION. PROGRAM-ID. RemovDir. DATA DIVISION. WORKING-STORAGE SECTION. *  Pathname of directory to remove. 01 DirPath   PIC X(256). *  Reserved by OS/2, must be set to 0. 01 Reserved  PIC 9(8) COMP-5 VALUE 0. PROCEDURE DIVISION. *   Prompt the user for the directory pathname, and terminate *   it with a null. DISPLAY &quot;Enter pathname of directory to remove:&quot;. ACCEPT DirPath. INSPECT DirPath REPLACING FIRST &quot; &quot; BY X&quot;00&quot;. *   Make the API call. CALL &quot;__DosRmDir&quot; USING BY VALUE    Reserved, BY REFERENCE DirPath. *   Check if an error occurred. IF RETURN-CODE = 0 THEN DISPLAY &quot;The directory has been removed.&quot; ELSE DISPLAY &quot;ERROR: &quot; RETURN-CODE DISPLAY &quot;Directory is root, not found, or not empty.&quot; CALL X&quot;E5&quot; END-IF. STOP RUN. Copyright Microsoft Corporation 1990.