News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

RemoveDirectory problem

Started by Nilrem, March 28, 2005, 11:17:48 PM

Previous topic - Next topic

Nilrem

this is my basic code:

buffer2 db 260 dup (?)
buffer3 db 260 dup (?)
buffer4 db "Program Files\Internet Explorer\1033",0

invoke GetSystemDirectory, addr buffer2, sizeof buffer2
xor edi,edi
    xor esi,esi
mov edi,offset buffer3               ; put start of destination in EDI
    mov esi,offset buffer2 ; put start of source in ESI
    mov ecx,3                            ; set number of bytes to move
    rep movsb
invoke lstrcat, addr buffer3, addr buffer4
invoke RemoveDirectory, addr buffer3
   
invoke MessageBox, NULL, addr buffer3, addr buffer2,MB_OK
invoke RtlZeroMemory, OFFSET buffer3, SIZEOF buffer3


The messagebox shows the correct directory to delete, but it just isn't deleting it. Please help me, I tried searching on google but I couldn't relate the .NET code back to asm. Thanks. Hi btw.

EDIT

I'm an idiot I never realised it was an api, and shock horror -
QuoteThe path must specify an empty directory
. Damn. I need to delete the directorie's contents not really the directory but I thought removing the directory would remove the contents (I am not supposed to know the contents just delete whatever is there).

donkey

You might think about using the shell functions to do this. I did something similar for an addin to RadASM. Sort of defunct now as Ketil incorporated part of the code directly in the IDE but it was fairly straight forward...

LOCAL sfo :SHFILEOPSTRUCT
LOCAL sfoabort :DWORD

mov eax,[hDlg]
mov sfo.hwnd,eax
mov sfo.wFunc,FO_DELETE
mov sfo.pFrom,OFFSET FileList
mov sfo.pTo,NULL
mov sfo.fFlags,FOF_NOERRORUI or FOF_SILENT or FOF_ALLOWUNDO
lea eax,sfoabort
mov sfo.fAnyOperationsAborted,eax
mov sfo.lpszProgressTitle, OFFSET szTitle
mov sfo.hNameMappings,NULL
invoke SHFileOperation,ADDR sfo

invoke RemoveDirectory,OFFSET RootPath


The FileList variable would contain the name of the files, usually %RootPath%\*.*, FO_DELETE is recursive (unless FOF_NORECURSION is specified) so it will remove any folders for you as well (unless FOF_FILESONLY is specified).
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Nilrem

Can't quite get the hang of it.


buffer2 db 260 dup (?)
buffer3 db 260 dup (?)
buffer4 db "Program Files\Internet Explorer\1033",0
FileList db "\*.sys",0

invoke GetSystemDirectory, addr buffer2, sizeof buffer2
xor edi,edi
    xor esi,esi
mov edi,offset buffer3               ; put start of destination in EDI
    mov esi,offset buffer2 ; put start of source in ESI
    mov ecx,3                            ; set number of bytes to move
    rep movsb
invoke lstrcat, addr buffer3, addr buffer4
invoke lstrcat, addr buffer3, addr FileList

mov eax,[hWnd]
mov sfo.hwnd,eax
mov sfo.wFunc,FO_DELETE
mov sfo.pFrom,OFFSET FileList
mov sfo.pTo,NULL
mov sfo.fFlags,FOF_NOERRORUI or FOF_SILENT or FOF_ALLOWUNDO
lea eax,sfoabort
mov sfo.fAnyOperationsAborted,eax
mov sfo.lpszProgressTitle, OFFSET MsgBoxCaption
mov sfo.hNameMappings,NULL
invoke SHFileOperation,ADDR sfo
invoke RemoveDirectory,OFFSET buffer3
   
invoke MessageBox, NULL, addr buffer3, addr buffer2,MB_OK
invoke RtlZeroMemory, OFFSET buffer3, SIZEOF buffer3


invoke Sleep, 1000



Thanks for helping. Also any papers on these shell commands because otherwise I'm just copying not learning? Thanks again.

donkey

The FileList buffer must contain a fully qualified path, you have \*.sys in it, that is not fully qualified. When I said %RootPath% I meant the full path of the folder you wished to delete, I should have been more clear but the name was practical in the context of the program it was in, looking at it now I see where it might be misunderstood.

Quote from: MSDN - SHFILEOPSTRUCT StructureAddress of a buffer to specify one or more source file names. These names must be fully qualified paths. Standard Microsoft MS-DOS wild cards, such as "*", are permitted in the file-name position.

Try using...

C:\Program Files\Internet Explorer\1033\*.sys

However if there are files that do not have the extension SYS in the folder they will not be deleted and you will still not be able to remove the directory.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Nilrem

I did actually know that, I forgot to change FileList to buffer3 lol. It works but it asks the user if it is ok to delete the files. I'd rather avoid this annoyance, is it just a case of changing a flag setting?

Edit:

I see it was just a case of a flag setting:
FOF_NOCONFIRMATION

Thanks a lot, worked like a treat. Ta Donkey!  :U