Hello Conor,
Thanks but it invokes an error message:
'Cannot delete file:cannot read from the source file or disk'
Would this have anything to do with WinXP administration rights? Although I can
delete all manually OK.
Alistair+
procedure TForm1.FormShow(Sender: TObject);
var
R: TShFileOpStruct;
foldername:string;
begin
foldername:='c:\temp';
If not DirectoryExists(FolderName) then Exit;
FolderName := IncludeTrailingBackslash(FolderName);
FolderName := FolderName + '*.*';
FillChar(R, SizeOf(r), 0);
r.wFunc := FO_DELETE;
r.pFrom := PChar(FolderName);
r.fFlags := FOF_NOCONFIRMATION;
if((ShFileOperation(r) = 0) and //<=== error here
(not r.fAnyOperationsAborted)) then
;
close;
end;
Tuesday, November 12, 2002, 9:13:54 AM, you wrote:
CB> To clarify, the second parameter to my function below (LeaveFolder)
CB> specifies whether or not to delete the actual folder you specify, or just to
CB> empty it of all it's files and subfolders.
CB> The ShellAPI unit can be very useful for things like this. The same
CB> ShFileOperation can be used for other things like copying files, and will
CB> throw up the standard Windows progress dialog etc, depending on which flags
CB> you set and how long Windows reckons the operation will take.
CB> Cheers,
CB> Conor
CB> -----Original Message-----
CB> From: Conor Boyd [mailto:Conor.Boyd@;treasury.sungard.com]
CB> Okay, here you go. This should be much tidier than shelling out to a
CB> command prompt, since it's using a Windows OS Shell function.
CB> This works on 95, NT, and above, according to the Microsoft SDK help.
CB> uses ShellApi, FileCtrl;
CB> function DeleteFolder(FolderName: String; LeaveFolder: Boolean) : Boolean;
CB> var
CB> R: TShFileOpStruct;
CB> begin
CB> Result := False;
CB> If not DirectoryExists(FolderName) then Exit;
CB> FolderName := IncludeTrailingBackslash(FolderName);
CB> If LeaveFolder then begin
CB> FolderName := FolderName + '*.*';
CB> end else begin
CB> if FolderName[Length(FolderName)] = '\' then begin
CB> Delete(FolderName,Length(FolderName),1);
CB> end;
CB> end;
CB> FillChar(R, SizeOf(r), 0);
CB> r.wFunc := FO_DELETE;
CB> r.pFrom := PChar(FolderName);
CB> r.fFlags := FOF_ALLOWUNDO OR FOF_NOCONFIRMATION;
CB> Result := ((ShFileOperation(r) = 0) and (not r.fAnyOperationsAborted));
CB> end;
CB> Using the ShFileOperation function and specifying the FOF_ALLOWUNDO flag
CB> will also make use of your Recycle Bin. ;-)
CB> If you want to tweak it, you should be able to find out more info from the
CB> SDK help that comes with Delphi.
CB> Enjoy...
CB> Cheers,
CB> Conor
CB> ---------------------------------------------------------------------------
CB> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
CB> Website: http://www.delphi.org.nz
CB> To UnSub, send email to: [EMAIL PROTECTED]
CB> with body of "unsubscribe delphi"
CB> Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
--
Regards,
Alistair+
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/