(Collect and organize) masm32 file and folder operation code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.