Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use the SHFileOperation function. The nice thing about using SHFileOperation is you have the option of deleting the files to the recycle bin and you get the normal API animations so the user will know what is going on. The downside is the delete will take a little longer than Jeff's code.</p> <p>There are several wrappers out there. I use this free wrapper from BP Software. The entire wrapper file is only 220 lines and is easy to read and use. I don't install this as a component. I have found it easier to add this unit to my project and just Create and free the object as needed.</p> <p>Update: The download link for the BP Software site is no longer valid. There is an <a href="http://cc.embarcadero.com/Item/15248" rel="nofollow noreferrer">older version on the Embarcadero website</a>.</p> <blockquote> <p>TSHFileOp (1.3.5.1) (3 KB) <br>May 31, 2006 <br>TComponent that is a wrapper for the SHFileOperation API to copy, move, rename, or delete (with recycle-bin support) a file system object.</p> </blockquote> <p>The file name parameter for SHFileOperation supports MS DOS style wildcards. So you can use the component like this:</p> <pre><code> FileOps := TSHFileOp.Create(self); FileOps.FileList.Add(DirectoryName + '\*.jpg'); FileOps.HWNDHandle := self.Handle; FileOps.Action := faDelete; FileOps.SHOptions := [ofAllowUndo, ofNoConfirmation, ofFilesOnly, ofSimpleProgress]; FileOps.Execute; </code></pre> <p>I usually show the "Are you sure" message myself so I always pass the ofNoConfirmation flag so Windows does not ask again.</p> <p>If you don't want to delete every jpg file or you need to delete from multiple directories you can add full file names or different paths with wild cards to the FileList string list before calling execute.</p> <p>Here is the <a href="http://msdn.microsoft.com/en-us/library/bb762164(VS.85).aspx" rel="nofollow noreferrer">MSDN Page for SHFileOperation</a><br> Note that SHFileOperation has been replaced by IFileOperation starting with Windows Vista. I have continued to use SHFileOperation on Windows Vista without any problems.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload