Search code examples
windowswinapiassemblymkdirtasm

Creating/removing directory using assembler (tasm) on windows


I have to write a TASM program which creates and removes directory, but I found example of creating file only.

model small
.data
    handle dw 0
    filename db "file2.txt",0
.stack 256
.code
main:

    mov ax,@data
    mov ds,ax

    mov ah,3ch 
    mov cx,1         
    lea dx,filename 
    int 21h 
    jc exit

    mov handle,ax
exit:
    mov ax,4c00h
    int 21h
end main

How i can modify this code for creating directory instead of file? And how I can remove created firectory?


Solution

  • I had to use masm and winapi. Here is the my sample code

    .586
    .model flat, stdcall
    option  casemap:none
    includelib kernel32.lib
    includelib shell32.lib
    include windows.inc
    include kernel32.inc
    
    .const
        sDir db 'folder', 0
        
    .code
        Main PROC
            invoke CreateDirectoryA, OFFSET sDir, NULL
            invoke Sleep, 2000d
            invoke RemoveDirectoryA, OFFSET sDir
            invoke Sleep, 2000d
            invoke ExitProcess, NULL
        Main ENDP
    
    end Main