1. delete folders and all their subdirectories and files (directory tree)
Include masm32rt. inc
; Ssssssssssssssssssssssssssssss
. Data
; Ssssssssssssssssssssssssssssss
Fileop shfileopstruct <>
Dir DB "C: \ Users \ Alex \ appdata \ Local \ Temp", 0
; Ssssssssssssssssssssssssssssss
. Code
; Ssssssssssssssssssssssssssssss
Start:
MoV fileop. wfunc, fo_delete
MoV fileop. pfrom, offset dir
MoV fileop. fflags, fof_noconfirmation
Invoke shfileoperation, ADDR fileop
Invoke exitprocess, 0
End start
2. Get the file name from the file description
Method 1: Use the Windows API function-pathfindfilename
Prototype: ptstr pathfindfilename (_ in ptstr ppath );
See http://msdn.microsoft.com/en-us/library/windows/desktop/bb773589 (V = vs.85). aspx
Method 2:
; Data
String1 DB "C: \ windows \ system32 \ calc.exe", 0
(...)
; Proc
Extractfilename proc lppath: DWORD
MoV ESI, lppath
Petla:
MoV Al, [esi]
INC ESI
Test Al, Al
JZ koniec
CMP Al ,'\'
JNE petla
MoV edX, ESI
JMP petla
Koniec:
RET
Extractfilename endp
(...)
; Usage (result in edX-pointer to first character of a filename)
Invoke extractfilename, ADDR string1
; Show the result
Invoke MessageBox, 0, EDX, 0, 0
Method 3:
. 386
. Model flat, stdcall
Option Casemap: None
Include \ masm32 \ include \ windows. inc
Include \ masm32 \ include \ kernel32.inc
Include \ masm32 \ include \ user32.inc
Includelib \ masm32 \ Lib \ user32.lib
Includelib \ masm32 \ Lib \ kernel32.lib
; Ssssssssssssssssssssssssssssss
. Data
; Ssssssssssssssssssssssssssssss
G_msgcaption DB "Get File Name", 0
G_szfs1 DB "C: \ A \ a.txt", 0
G_szfs2 DB "C: B .txt", 0
G_szfs3 DB "c.txt", 0
; Ssssssssssssssssssssssssssssss
. Code
; Ssssssssssssssssssssssssssssss
;::::::::::::::::::::::::::::::::::::::: ::::::::::::::
Input: lpszfilespec = pointer to the file descriptor string (first address)
; Return Value: eax = 0. The file descriptor string pointed to by lpszfilespec is null.
; Eax> 0, whose value is the pointer to the file name string (first address)
;::::::::::::::::::::::::::::::::::::::: ::::::::::::::
Getfilename proc uses EDI lpszfilespec: DWORD
MoV eax, lpszfilespec
MoV EDI, eax
Test eax, eax
JZ @ getfilenamedone
Invoke lstrlen, eax
Test eax, eax
JZ @ getfilenamedone
Lea ECx, [eax + EDI]
@ Getfilenamenext:
CMP ECx, EDI
JB @ getfilenameson
MoV Al, [ECx]
CMP Al ,'\'
JZ @ getfilenameson
CMP Al ,':'
JZ @ getfilenameson
Sub ECx, 1
JMP @ getfilenamenext
@ Getfilenameson:
Lea eax, [ECx + 1]
@ Getfilenamedone:
RET
Getfilename endp
Start:
Invoke getfilename, offset g_szfs1
Invoke MessageBox, null, eax, offset g_msgcaption, mb_ OK
Invoke getfilename, offset g_szfs2
Invoke MessageBox, null, eax, offset g_msgcaption, mb_ OK
Invoke getfilename, offset g_szfs3
Invoke MessageBox, null, eax, offset g_msgcaption, mb_ OK
Invoke exitprocess, null
End start