Results 1 to 13 of 13

Thread: Delete a file in ASM?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Location
    Cleveland, Ohio
    Posts
    255

    Delete a file in ASM?

    How is this done? I saw very little documentation on it and I think it went something like,

    Code:
    lea dx, ptrtofilename;
    mov ah, 41h;
    but I wasn't entirely sure.. can anyone clarify?

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Delete a file in ASM?

    It depends. What instruction set are you using? Is it going to be 32-bit or 16-bit? If its 32-bit (well, MASM), it wouldn't be too hard.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Addicted Member
    Join Date
    Mar 2005
    Posts
    158

    Re: Delete a file in ASM?

    INT 21H Function 41H : Delete File
    This function deletes a file (but not read-only) from within a program. Load the address in the DX of an ASCII string containing the device path and filename, with no wild-card references:
    Code:
    ASCstrng DB 'd:\pathname', 00H ; ASCII string
    ...
    MOV AH,41H
    LEA DX, ASCstrng
    INT 21H
    A valid operation clears the carry flag, marks the filename in the directory as deleted, and releases the file's allocated disk space in the FAT. An error sets the carry flag and returns code 02, 03, or 05 in the AX.

    you should get yourself Ralf-Brown's Interrupt List
    http://www.cs.cmu.edu/afs/cs/user/ra...WWW/files.html
    if u felt my post make u happy ,
    then u could make me happy too by rating my post

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Delete a file in ASM?

    Thats compiler specific isn't it? I mean, the interrupts wouldn't work in 32-bit assembly?

    Which is why I asked what he was using..

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  5. #5
    Addicted Member
    Join Date
    Mar 2005
    Posts
    158

    Re: Delete a file in ASM?

    compiler specific?
    that is MS DOS (operating system) interrupt to delete a file, of course, you must using FAT filesystem.

    whether the interrupt would works in 32-bit windows... em.. could create a com file to try. i am not so sure, but i guess it should work.
    if u felt my post make u happy ,
    then u could make me happy too by rating my post

  6. #6
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Delete a file in ASM?

    I'll give it a test when I get my new PC.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  7. #7
    Addicted Member
    Join Date
    Mar 2005
    Posts
    158

    Re: Delete a file in ASM?

    k, just confirm, you can use the DOS interrupt to delete file, create directory and much more.
    Code:
    ORG 100h
    
    jmp start
    
    aa db 'c:\apple.txt',00h
    
    start:
    mov ah,41h
    mov dx,aa
    int 21h
    mov ax,4ch
    int 21h
    create a file in c:\apple.txt or wat sover place u want to put and (if change then modify the aa variable)
    i use fasm assembler (free and open source) http://flatassembler.net

    Code:
    fasm myfile.txt myfile.com
    Last edited by asmdev; Aug 26th, 2005 at 08:56 AM.
    if u felt my post make u happy ,
    then u could make me happy too by rating my post

  8. #8
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Delete a file in ASM?

    Nice. That will become very useful. I've always had to resort to calling API's. No doubt this would be alot faster aswell (without having to go through all the windows crap beforehand).

    Ta.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Delete a file in ASM?

    Uh, in Windows, you should be calling the APIs, not using DOS interrupts. It's always better to do it the supported way.

  10. #10
    Addicted Member
    Join Date
    Mar 2005
    Posts
    158

    Re: Delete a file in ASM?

    ya, so that the code works in FAT, NTFS or watever new FS microsoft introduce ;-p
    if u felt my post make u happy ,
    then u could make me happy too by rating my post

  11. #11
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Delete a file in ASM?

    Quote Originally Posted by penagate
    Uh, in Windows, you should be calling the APIs, not using DOS interrupts. It's always better to do it the supported way.
    True, but it's always good to experiment (if you've got the money, and decide to ruin your PC ).

    PS: How often do you change your avatar penagate? My god, its like you change it after every meal

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Delete a file in ASM?

    Change is healthy (or whatever). I refocused it again after twice being accused by RobDog of not seeing things properly

    Congrats on 2K posts BTW.

  13. #13
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Delete a file in ASM?

    lol. RobDog is wise.

    Ta

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width