This is the past DOS era of the compilation of source code, although has passed, but for the study of the assembly is still helpful, assembly language is just a basic programmer language, most people can grasp, not necessarily in-depth research.
;************************************************************************
;* *
; * Cleandoc 1.2 (C) 1997 Ronsoft. *
;* *
; * This is a simple litte assembler the cleans out *
* The Documents folder in the Start menu. *
; * This is version 1.2 *
; * There ' s no command line switches and stuff. *
; * It gives NO messages if everything goes allright. *
; * It Check for a environment variable called Cleandir and Cd:s *
; * Down to that DIR-if the variable is found. If not it uses *
; * The default windowsrecent directory and Deletes (unlinks) *
; * EVERYTHING it finds there, and cd:s back to where it started *
; * from. *
;* *
; * Comments, suggestions: *
; * Ronald Nordberg. *
; * Silverv 刧 en 3 *
* 907, Ume? *
; * Sweden. *
; * http://home2.swipnet.se/~w-20064 *
; * christine.martinson@swipnet.se *
;* *
; * This program ARE copyrighted freeware. * *
;* *
;************************************************************************
; some euqates for readability
KBD equ 16h; keyboard IRQ
Msdos equ 21h; MSDOS IRQ
Reset equ 0DH;d ISK Reset
Dfopen equ 0fh; open Disk File
Dfclose equ 10h; close Disk File
SEARCHF equ 11h; search
Searchn equ 12h; Search Next
Seqread equ 14h; sequential disk read
Seqwrite equ 15h; "" Write
Getdisk equ 19h; Get current disk (default)
SETDTA equ 1ah; Set disk transfer area address
Setdir equ 3BH; Set current directory
Createf equ 3ch; create file with handle
OPENF equ 3DH; open file with handle
Closef equ 3eh; close file with handle
READF equ 3fh; read from file with handle
Writef equ 40h; write to file with handle
unlink equ 41h; UNLINK (delete file)
Getdir equ 47h; get current directory
AllocMem equ 48h; Allocate memory
Freemem equ 49h; free memory
Changebs equ 4ah; change block size
FindFirst equ 4eh;
FindNext equ 4fh; Find Next file
Exit equ 4c00h; Msdos exit
EnviR equ 2ch; offset environment block
[BITS 16]; NASM STUFF!?
[ORG 100h]
mov ax,cs; Get code segment
MOV ds,ax;
mov [comseg],ds
mov [extseg],es
; ************************ Setup and preparing ***************************
Main
MOV ah,setdta; set our Dta-area
mov dx,mydta; buffer for it
int msdos; Call DOS
mov ah,getdisk; get default Drive
int msdos; Call DOS
Add al,41h;d Rive in Al, make it ASCII
mov byte [curdir],al; fill buffer with name (A:.. etc
mov byte [path],al; default path
MOV word [curdir+1], ":"; Copy Separator to Path
mov si,curdir;p ointer Path buffer
Add si,3 offset Doscall part
mov ah,getdir; get current dir
MOV dl,0 0 = default
int msdos; Call DOS
Jnc Diskok; ok
MOV bx,errt0 could not find current dir?? If You
JMP Errout get a error here to you probably have
Diskok: Forgot to turn on Your computer.
Call getenv Check out if any ENV var
CMP Dx,-1. Was it there
Je findfile; yeahh
mov dx,path noo way, use default path
MOV ah,setdir CD down
int msdos; Call DOS
Jnc FindFile all OK
MOV bx,errt1; error
JMP Errout; skip
; *************************** the delete file loop ***********************
FindFile:
mov Ah,findfirst; = If the files out there
MOV cx,0fh all Files
mov dx,files; our NULL terminated filname (*.*)
int msdos;d o the stuff
Jnc Delit All OK, must delete the
JMP GoBack error, CD back and Skip
Found:; found something
mov dx,files; files (*.*)
mov Ah,findnext; the function
int msdos; Call DOS
JC GoBack No more files, quit
Delit:
MOV ah,unlink; UNLINK (delete) file
mov dx,mydta;p ointer Disk Transfer Area
Add dx,30; offset Filename
int Msdos;d Elete It
Jnc found;d eleted OK
MOV bx,errt2; Could not delete it????
Call write; let us know
mov bx,mydta; show wich file
add bx,30; offset filename in DTA
Call write, write out filename
mov bx,linefeed; linefeed
JMP Errout and Skip
GoBack
MOV ah,setdir; CD back to Origin
mov dx,curdir;p ath to dir
int Msdos;d o it
Jnc quit; all OK, proceed
mov bx,errt1; error, get text
; *************************** Errorexit ***********************
Errout:call write; show errormessage
Quit
XOR Eax,eax;
MOV ax,exit; MS-DOS successful exit
int msdos; Back to the operating system
; ***************** get environment var if any *****************
Getenv
Push es; now check if there "s any
Push DS; environment variable
mov es,[es:+2ch]; es:di points at Environment
XOR Di,di which is paragraph-aligned
Floop:
CMP byte [es:di],0; if we got 2 zeroes in a row
Jne Goon; We are at the end of the ENV
CMP byte [es:di+1],0; variables
Je eout
Goon
EQUAL:CMP byte [Es:di], ' C ', it our variable?
Jne flop
Inc byte Di
CMP byte [Es:di], ' L '
Jne flop
Inc byte Di
CMP byte [Es:di], ' E '
Jne flop
Inc byte Di
CMP byte [Es:di], ' A '
Jne flop
Inc byte Di
CMP byte [Es:di], ' N '
Jne flop
Inc byte Di
CMP byte [Es:di], ' D '
Jne flop
Inc byte Di
CMP byte [Es:di], ' I '
Jne flop
Inc byte Di
CMP byte [Es:di], ' R '
Jne flop
Sign:inc byte di;d UMP the R
Inc byte Di;d UMP the =
mov ax,es make ds:dx point to string we found
MOV Ds,ax
MOV Si,di
MOV Bx,si
MOV dx,bx
MOV ah,setdir func Set current Directory (CD)
int Msdos;d o it
Jnc Envok; all OK, proceed
MOV dx,0 clear flag (use default dir)
JMP Eout;
Flop:inc byte di; next byte
CMP byte [es:di],0 a 0?
Jne flop; Noo
Inc. byte di; yeahh, dump it
JMP Floop Check if two
Envok:mov dx,-1
Eout:pop DS
Pop es
Ret
;*************************************************************************
* Writes out of the NULL terminated text supplied in BX. *
; * or writes out DATA,BX and SIZE,CX if called at Lwrite. *
;*************************************************************************
Write:pusha
mov si,bx; Copy to Si
MOV cx,0 clear Count
WLOOP:LODSB load AL with SI
CMP al,0 end of line?
Je lwrite; yeahh
Inc CX; No, incrase byte count
JMP wloop; test next byte
Lwrite:mov dx,bx text address in DX
MOV bx,1 filehandle standard output = 1
MOV Ah,writef; MS-DOS WriteFile with handle is 040
int msdos; write buffer to standard output
Popa
RET;d One
; ************************ DATA and BSS stuff ***************************
COMSEG:DW 0
EXTSEG:DW 0
Utext:db "Cleandoc V1.2 (C) 1997 Ronsoft", 13,10,0
Errt0:db "could not find current directory!", 13,10,0
Errt1:db "Directory not found.", 13,10,0
Errt2:db "Could not delete", 0
Path:db ": Windowsrecent", 0;d efault path without DRIVE
Files:db "*.*", 0
Linefeed:db 13,10,0
MYDTA Times 128 db 0, use 128 bytes as DTA NASM stuff!
CurDir Times DB 0, use 4 bytes for current dir
End