I had the same error when I was re-testing that function this morning. There isn't really any error checking in my function; check that you're correctly specifying the folder to delete.
The other possibility is that you have an Explorer window or similar open which will stop Windows from being able to delete the folder (although that's expected functionality - you'll get the same if you try to delete a folder manually when you have an Explorer window open in a subfolder). The ShFileOperation function is definitely the way for you to go, you might just have to tweak the function or debug it to get it working correctly for you. Step through the code and inspect the r.pFrom value and see if it's set to the folder you expect it to be. Can't really help you much more than that, although it shouldn't be a rights issue if you can delete it manually. Good luck, Conor -----Original Message----- From: [EMAIL PROTECTED] [mailto:bigal@;xtra.co.nz] 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/ --------------------------------------------------------------------------- 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/