Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete file to recycle bin, msg error 2

Status
Not open for further replies.

michaenh

Programmer
Aug 7, 2002
205
NO
Hi Delphi experts!

Here is my code:
uses ShellAPI;

procedure TMainForm.RecycleBin(FileToRecycle: string);
var
SHF: TSHFileOpStruct;
begin
with SHF do begin
Wnd := Application.Handle;
wFunc := FO_DELETE;
pFrom := PChar(FileToRecycle);
fFlags := FOF_NOCONFIRMATION or FOF_ALLOWUNDO;
end;
SHFileOperation(SHF);
end;

Some file works well with this proc, but others I get this error msg:
Cannot delete file: Cannot read from the source file or disk
But the source is there and the FileToRecycle path is correct..

Any ideas?? or other methods to delete file to recycle bin??

Millions of thanks
Michael
 
hi

Is the path/filename correct in the FileToRecycle variable?

In the example I have, they have appended 2 #0s, like this (not sure why but you could try it).

pFrom := pchar(sFilename+#0+#0);

Also, do you not need an AND condition in the fFlags?

I haven't used this function call much, so I'm stabbing in the dark a little here.

hope its helpful, anyway
lou
 
Hi weez.

you are great! thanks for the fast respons.. :eek:)

with SHF do begin
Wnd := Application.Handle;
wFunc := FO_DELETE;
pFrom := PChar(FileToRecycle+#0+#0);
fFlags := FOF_NOCONFIRMATION;
end;
SHFileOperation(SHF);

there is my code.. you had to add +#0+#0
as your question to AND FOF_ALLOWUNDO in the fFlags..
you dont need at all because I am creating my own dialog, not the deafult icrosoft.. dialog..

thanks! thanks! thanks!
Michael

 
Sorry.. my fault.. :eek:)
You have to add OR FOF_ALLOWUNDO fFlags if you want the file to send to the recycle bind without any Microsoft default dialog box. If you add AND FOF_ALLOWUNDO then the default box will pop up.

michael
 
hi Michael

Just saw your last msg and was wondering why FOF_ALLOWUNDO was not there.

Glad you've sorted it.

lou
 
Hi Weez,michaenh and other Experts

uses ShellAPI;

procedure TMainForm.RecycleBin(FileToRecycle: string);
var
SHF: TSHFileOpStruct;
begin
with SHF do begin
Wnd := Application.Handle;
wFunc := FO_DELETE;
pFrom := PChar(FileToRecycle+#0+#0);{Help full weez tip}
fFlags := FOF_ALLOWUNDO;
end;
SHFileOperation(SHF);
end;


This code worked for me quite well, except in win98 its not showing any confirmation if any body know the reason
Pls do Help
Jpattom
 
Hi.

I have not tried the application on win98, but I also do not use the Microsoft default dialog box...

function TForm.RecycleBin(FileToRecycle: string): boolean;
var
SHF: TSHFileOpStruct;
begin
with SHF do begin
Wnd := Application.Handle;
wFunc := FO_DELETE;
pFrom := PChar(FileToRecycle+#0+#0);{Help full weez tip}
fFlags := FOF_NOCONFIRMATION OR FOF_ALLOWUNDO;
end;
SHFileOperation(SHF);
end;

I create my own dialogs with another language...

if RecycleBin(..) then
MessageDlg(...) //Cool the file is gone
else
MessageDlg(...) //file delete error

cheers,
mha
 
hi again.

Forgot to add try.. except..
and result to true or false.. in the last function example..
answered to quick..

:)
 


Hi michaenh
Thanx For the earliets respond
But I dont know why Our QA insist on the Defualt Confirmation Dialog box from the windows.
Once agin thnx for the reply
JPattom
 
hi again

It is strange that the Defualt Confirmation Dialog box doesn't show in win98. Have you tried it on a another win98 computer? or it is general.

I will try the proc later(on a rainy day) on a computer with 98sys.

cheers so long,
I'll be back... :)
 
Hi michaenh
I am very Sorry to say tht this mistake from the QA side, tht their system's 'Display Delete Confirmation was off' this also took my preciuos time sorry to disturb u for this.
(Once again the QAs are on the looser side in the never ending battle)
any way thax for the help,
the thread u started helped me to fix

Cannot delete file: Cannot read from the source file or disk

thax for Mr Weez too

ha ha u dont have to wait for a rainy day


thank fully
JPattom
 
hi JPattom

Glad you sorted it. By the way, I'm not a 'Mr' - well I wasn't the last time I checked anyway [smile2]

lou

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top