• Is there an api call to remove an entire directory tree?

    From T@21:1/5 to All on Wed May 21 20:54:12 2025
    Is there an api call to remove an entire directory tree?

    Not just one empty directory. Everything!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Thu May 22 08:09:31 2025
    T,

    Is there an api call to remove an entire directory tree?

    Not just one empty directory. Everything!

    Like SHFileOperation (https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shfileoperationa)
    does ?

    Be carefull though. Just a little mistake and ....

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From T@21:1/5 to R.Wieser on Wed May 21 23:35:53 2025
    On 5/21/25 11:09 PM, R.Wieser wrote:
    T,

    Is there an api call to remove an entire directory tree?

    Not just one empty directory. Everything!

    Like SHFileOperation (https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shfileoperationa)
    does ?

    Be carefull though. Just a little mistake and ....

    Regards,
    Rudy Wieser




    I found that. And it was a bit scary.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Thu May 22 13:10:23 2025
    T,

    I found that. And it was a bit scary.

    :-) Which part, the "delete everything" part, or the structure ? In the
    latter case, its less complex than you might consider it to be :

    - - - - - - - - - - - - - - - - - - - - - - - - -

    SHFILEOPSTRUCT struc
    SHFO_hwnd dd ?
    SHFO_wFunc dd ?
    SHFO_pFrom dd ? ;must be terminated with a double zero.
    SHFO_pTo dd ?
    SHFO_fFlags dd ?
    SHFO_fAnyOperationsAborted dd ?
    SHFO_hNameMappings dd ?
    SHFO_lpszProgressTitle dd ?
    ends

    lea ebx,[@@rSHFO]
    call RtlZeroMemory,ebx,size SHFILEOPSTRUCT

    mov [ebx].SHFO_wFunc,FO_DELETE
    mov [ebx].SHFO_pFrom,offset @@TXT_PathZZ
    mov [ebx].SHFO_fFlags,FOF_NOCONFIRMATION or FOF_NOERRORUI or FOF_SILENT
    mov [ebx].SHFO_lpszProgressTitle,offset @@TXT_Nul

    call SHFileOperationA,ebx

    - - - - - - - - - - - - - - - - - - - - - - - - -

    Remark: @@TXT_PathZZ must be terminated with a double Zero (it can be used
    to provide multiple filenames).
    @@TXT_Nul is an empty string.

    Hope that helps.

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From T@21:1/5 to R.Wieser on Thu May 22 16:28:23 2025
    On 5/22/25 4:10 AM, R.Wieser wrote:
    T,

    I found that. And it was a bit scary.

    :-) Which part, the "delete everything" part, or the structure ? In the latter case, its less complex than you might consider it to be :

    - - - - - - - - - - - - - - - - - - - - - - - - -

    SHFILEOPSTRUCT struc
    SHFO_hwnd dd ?
    SHFO_wFunc dd ?
    SHFO_pFrom dd ? ;must be terminated with a double zero.
    SHFO_pTo dd ?
    SHFO_fFlags dd ?
    SHFO_fAnyOperationsAborted dd ?
    SHFO_hNameMappings dd ?
    SHFO_lpszProgressTitle dd ?
    ends

    lea ebx,[@@rSHFO]
    call RtlZeroMemory,ebx,size SHFILEOPSTRUCT

    mov [ebx].SHFO_wFunc,FO_DELETE
    mov [ebx].SHFO_pFrom,offset @@TXT_PathZZ
    mov [ebx].SHFO_fFlags,FOF_NOCONFIRMATION or FOF_NOERRORUI or FOF_SILENT
    mov [ebx].SHFO_lpszProgressTitle,offset @@TXT_Nul

    call SHFileOperationA,ebx

    - - - - - - - - - - - - - - - - - - - - - - - - -

    Remark: @@TXT_PathZZ must be terminated with a double Zero (it can be used
    to provide multiple filenames).
    @@TXT_Nul is an empty string.

    Hope that helps.

    Regards,
    Rudy Wieser



    Thank you. It will take a bit to sink in

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Fri May 23 10:09:56 2025
    T,

    Thank you. It will take a bit to sink in

    Youre welcome.

    You can leave out the line with "FOF_SILENT", so you will, IIIRC, get a
    dialog to look at (to confirm your choice)

    Suggestion: try it on an empty folder (on an empty or not-really-important thumbdrive perhaps ?). Or better yet, an empty folder you created some
    testing folders and files* in (using a batch file ?). At least, thats what
    I did when I first tested the function.

    * perhaps giving one or two the read-only and/or system attributes ? Just
    to see how the call deals with those (and don't forget to check the returned value).

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From T@21:1/5 to R.Wieser on Fri May 23 04:28:33 2025
    On 5/23/25 1:09 AM, R.Wieser wrote:
    T,

    Thank you. It will take a bit to sink in

    Youre welcome.

    You can leave out the line with "FOF_SILENT", so you will, IIIRC, get a dialog to look at (to confirm your choice)

    Suggestion: try it on an empty folder (on an empty or not-really-important thumbdrive perhaps ?). Or better yet, an empty folder you created some testing folders and files* in (using a batch file ?). At least, thats what
    I did when I first tested the function.

    * perhaps giving one or two the read-only and/or system attributes ? Just to see how the call deals with those (and don't forget to check the returned value).

    Regards,
    Rudy Wieser




    Did your test whack files with file locks on them?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Fri May 23 14:28:15 2025
    T,

    Suggestion: try it on an empty folder [snip]
    ...
    Did your test whack files with file locks on them?

    I can't remember that I ever tried that. When you do you will likely get a "failed" result from the call (and it might stop mid-deleting). Do try !

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From T@21:1/5 to R.Wieser on Fri May 23 17:21:21 2025
    On 5/23/25 5:28 AM, R.Wieser wrote:
    T,

    Suggestion: try it on an empty folder [snip]
    ...
    Did your test whack files with file locks on them?

    I can't remember that I ever tried that. When you do you will likely get a "failed" result from the call (and it might stop mid-deleting). Do try !

    Regards,
    Rudy Wieser




    Rats, I was looking for a hammer to replace

    FastCopy.exe /CMD=delete /no_confirm_del /balloon=FALSE /auto_close DirectoryPath

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Sat May 24 09:38:05 2025
    T,

    Rats, I was looking for a hammer to replace

    FastCopy.exe /CMD=delete /no_confirm_del /balloon=FALSE /auto_close DirectoryPath

    I just googled for that program, and found that its deletion method seems to
    be quite a bit more complex than what SHFileOperation offers. One of the things it does is that it will monitor files it can't directly delete, to delete them when they get closed. IOW, FastCopy could be running for
    hours(?) if that is how long the to-be-deleted file stays open (logfiles
    anyone ?)

    If-and-when SHFileOperation aborts the deletion process when it encounters
    the first un-deletable file/folder (as I think it does *) than you could
    write your own (recursive) directory-traversal method, and just continue
    when a file/folder can't be deleted (and, in the end, show a message with
    the number of un-deletable files ?).

    * I do not see a "continue on failure to delete" flag anywhere.

    You would than be left with a pruned folder tree, only holding the
    un-deletable files. Not quite the wanted result, but way better than a halfway deleted tree, with no indication which file stopped the deletion process.

    A possible "hammer" solution could be to use "ShellExecute" or perhaps even "CreateProcess" to run FastCopy.exe. Ugly, but it would work.

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From T@21:1/5 to R.Wieser on Sat May 24 05:41:19 2025
    On 5/24/25 12:38 AM, R.Wieser wrote:
    T,

    Rats, I was looking for a hammer to replace

    FastCopy.exe /CMD=delete /no_confirm_del /balloon=FALSE /auto_close
    DirectoryPath

    I just googled for that program, and found that its deletion method seems to be quite a bit more complex than what SHFileOperation offers. One of the things it does is that it will monitor files it can't directly delete, to delete them when they get closed. IOW, FastCopy could be running for hours(?) if that is how long the to-be-deleted file stays open (logfiles anyone ?)

    If-and-when SHFileOperation aborts the deletion process when it encounters the first un-deletable file/folder (as I think it does *) than you could write your own (recursive) directory-traversal method, and just continue
    when a file/folder can't be deleted (and, in the end, show a message with
    the number of un-deletable files ?).

    * I do not see a "continue on failure to delete" flag anywhere.

    You would than be left with a pruned folder tree, only holding the un-deletable files. Not quite the wanted result, but way better than a halfway deleted tree, with no indication which file stopped the deletion process.

    A possible "hammer" solution could be to use "ShellExecute" or perhaps even "CreateProcess" to run FastCopy.exe. Ugly, but it would work.

    Regards,
    Rudy Wieser



    I have found a way to use robocopy to mirror an empty
    directory. It has the result of wiping whatever was
    previously there.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Sat May 24 15:59:52 2025
    T,

    I have found a way to use robocopy to mirror an empty
    directory. It has the result of wiping whatever was
    previously there.

    :-) There are multiple ways leading to rome.

    Though be carefull with external dependancies like that. While FastCopy
    seems to come with the OS, RoboCopy doesn't.

    Hmmm... I just remembered : "RD /S foldername" could/would possibly work as well - though you would need to run it using CMD.exe : "CMD /C RD /S foldername"

    But to be honest, I would rather use SHFileOperation. Everything nicely
    packed in a single OS-provided call. Or even a bit of code walking the directory tree, (and in your case) deleting everything in it (I've used my tree-walking code for in several programs).

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Sat May 24 17:07:26 2025
    T,

    SHFileOperation is not enough of a hammer
    for my needs. I was hoping so, but ...

    In what way its not enough ? Be carefull if RoboCopy seems to delete
    locked files too - a waiting for a file to become unlocked might give some
    side effects* you need to keep aware of.

    * like a folder list upto the to-be-deleted file you should not try to put a new file in - it could easily disappear when RoboCopy finishes up (something
    to check?).

    You got FastCopy and RoboCopy backwards.
    Or I read your sentence backwards -- it
    happens.

    Neither. I interpreted your "Rats, I was looking for a hammer to replace"
    as that you already had a FastCopy solution, but (where writing a program
    where you) wanted to get rid of it in favour of an API call.

    An interpretation which definitily isn't /my/ fault ofcourse. :-) <whistle>

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From T@21:1/5 to R.Wieser on Sat May 24 07:27:37 2025
    On 5/24/25 6:59 AM, R.Wieser wrote:
    T,

    I have found a way to use robocopy to mirror an empty
    directory. It has the result of wiping whatever was
    previously there.

    :-) There are multiple ways leading to rome.

    Though be carefull with external dependancies like that. While FastCopy seems to come with the OS, RoboCopy doesn't.

    Hmmm... I just remembered : "RD /S foldername" could/would possibly work as well - though you would need to run it using CMD.exe : "CMD /C RD /S foldername"

    But to be honest, I would rather use SHFileOperation. Everything nicely packed in a single OS-provided call. Or even a bit of code walking the directory tree, (and in your case) deleting everything in it (I've used my tree-walking code for in several programs).

    Regards,
    Rudy Wieser



    Hi Rudy,

    SHFileOperation is not enough of a hammer
    for my needs. I was hoping so, but ...

    You got FastCopy and RoboCopy backwards.
    Or I read your sentence backwards -- it
    happens.

    W10:
    C:\>where robocopy.exe
    C:\Windows\System32\Robocopy.exe

    C:\>where fastcopy.exe
    INFO: Could not find files for the given pattern(s).

    https://fastcopy.jp/

    And ya, I know what you mean by dependencies.
    I was hoping to get rid of them with an API call.

    -T

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)