INT 21h AH=3Ah removes the directory named by the ASCIIZ path at DS:DX: RD (RMDIR) at the prompt. It removes only an empty directory, one with no entries but "." and "..".
| AX (CF = 1) | Why |
|---|---|
| 3 | path not found: there is no such directory |
| 5 | access denied: not empty, read-only, or the root directory |
| 16 (10h) | it is the current directory of its drive |
Hidden and system files count. DIR does not show them, so a directory can look empty and still fail with 5. To clear one, find its files with INT 21h AH=4Eh (with hidden and system bits in CX), clear a read-only attribute with INT 21h AH=43h, and delete each with INT 21h AH=41h; subdirectories have to be emptied and removed first.
No drive's current directory can be removed, not only the current drive's: change out of it first. The example goes into TESTDIR, tries to remove it from inside, then from its parent, then once more:
MOV AH, 39h ; make TESTDIRMOV DX, OFFSET DIR1INT 21hMOV AH, 3Bh ; and go into itMOV DX, OFFSET DIR1INT 21hMOV DX, OFFSET INM1MOV AH, 09hINT 21hMOV AH, 3Ah ; DOS: remove the directory named at DS:DXMOV DX, OFFSET SELF1 ; "..\TESTDIR": where we areINT 21hCALL RESULT ; error 16MOV AH, 3Bh ; up to the parentMOV DX, OFFSET UP1INT 21hMOV DX, OFFSET OUTM1MOV AH, 09hINT 21hMOV AH, 3AhMOV DX, OFFSET DIR1INT 21hCALL RESULT ; okMOV DX, OFFSET AGAINM1MOV AH, 09hINT 21hMOV AH, 3AhMOV DX, OFFSET DIR1INT 21hCALL RESULT ; error 3: it is goneDIR1 DB "TESTDIR", 0SELF1 DB "..\TESTDIR", 0UP1 DB "..", 0INM1 DB "rmdir while inside it: $"OUTM1 DB "rmdir from its parent: $"AGAINM1 DB "rmdir once more: $"RESULT PROC NEAR ; print "ok", or "error" and AX when CF = 1PUSHF ; keeps AX and CF for the callerPUSH AXMOV DX, OFFSET OKMSGJNC RESULT1MOV DX, OFFSET ERRMSGMOV AH, 09hINT 21hPOP AXPUSH AXCALL PDEC ; the error codeMOV DX, OFFSET CRLFRESULT1:MOV AH, 09hINT 21hPOP AXPOPFRETRESULT ENDPOKMSG DB "ok", 13, 10, "$"ERRMSG DB "error $"PDEC PROC NEAR ; print AX in decimal (changes AX BX CX DX)MOV BX, 10XOR CX, CX ; digits on the stackPDEC1:XOR DX, DXDIV BX ; AX = AX / 10, DX = the last digitPUSH DXINC CXOR AX, AXJNZ PDEC1PDEC2:POP DX ; the digits come back first to lastADD DL, "0"MOV AH, 02hINT 21hLOOP PDEC2RETPDEC ENDPCRLF DB 13, 10, "$"
DOSBox-X makes the error 16 check itself before it asks the host to delete the folder, since the host knows nothing about DOS's current directories. When the host refuses for another reason, DOSBox-X reports 5, as DOS does for a directory that is not empty.