Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Delete using recycle bin

Author
Message
Ben_UK78
15
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 9th Jan 2012 01:29
Hi all,

Is there a method for deleting files and folders to the recycle bin, not just erasing them permanently.

Can this be done using a windows dll call if not using a DP command?

Thanks for any help.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 9th Jan 2012 02:52 Edited at: 9th Jan 2012 02:59
There's a free utility for the win CMD line called Recycle.exe. This is needed because AFAIK there is no Microsoft cmd/DOS command that doesn't delete the file permanently,, making use of the recycle bin.

http://www.watchingthenet.com/send-deleted-files-to-the-recycle-bin-when-using-windows-command-prompt.html

I assume you could download and extract recycle.exe (there are other utils in the zip). Then execute Recycle.exe from within your program via the "execute file" command.

This is just a theory, I haven't actually tried it myself.

~ZENassem
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 9th Jan 2012 07:01 Edited at: 9th Jan 2012 07:02
There's API function that will delete to the recycle bin...

Here's an article (for Visual Basic 6, but you should be able to convert)
http://www.techrepublic.com/article/vb6-tip-deleting-files-to-the-recycle-bin-from-within-a-vb6-application/5439292

Ben_UK78
15
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 9th Jan 2012 09:03
That was the last page I looked at before posting this post, so at last I know I was on the right track.

Thanks very much. I'll have a crack at that method (thanks also for the above info about the external exe file, but I'll have a go at the windows call before resorting to external exe files).

If successful I will post the code here later.

(So if your reading this in 2 years time and there is no code - I failed)
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 9th Jan 2012 22:41
Here is a single function plug-in I just worked up.The source code is include. To use; copy the dll file to your compiler\plugins-user folder and use Recycle "filename" in dark basic.
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 9th Jan 2012 23:39
This dll works the same, only without the confirmation window.
Ben_UK78
15
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 10th Jan 2012 03:14
Thanks.

Ive tried using Shell32.dll and it's being a pain.

I've got it to delete, but it seems oddly directory dependant. Copying the project exe file and a test file around the hard disk it works to a point (up to 'The Game Creators' for example) and then stops working with SHFileOperation returning code 124. - an invalid path.

Is there something special about get dir() and using this to build a string that would make it work in one part of the directory structure and not another - I can't imagine what it would be. SHFileOperation demands double null terminated strings, but if it works in some locations then it can't be that?? I removed the read only flag from The Game Creators directory, but to no avail.

WickedX - do you have keyword files etc for your plugin. I've put it in the plugin folder, and DP complied the project, but it didn't do anything?
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 10th Jan 2012 04:00
Ok found the problem, use full paths. I should probably put this though some more tests, to see how it works deleting multiple file and such. I’ll check it out and post something tomorrow. Attached is the keyword file.
Ben_UK78
15
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 10th Jan 2012 04:41
Sadly it has the same error as my shell32.dll code.

If I give the string address myself (g_TESTFile$ = "C:\Test\Test1.txt") then it works fine

g_TESTFile$ = g_autodir_full_directory_path$ + "\TestText.txt"
make file g_TESTFile$
Recycle g_TESTFile$

Fails.

My own code does too though using this sort of thing:
Ben_UK78
15
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 10th Jan 2012 04:55
I should say the obvious, since it might just be a simple mistake above - the .txt names are from my multiple attempts. Its not just that I got the filename wrong! A
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 12th Jan 2012 03:39 Edited at: 12th Jan 2012 03:40
After some research it boils down to two things. Passing the function, string literals worked on Windows XP and Windows 7 just fine. Windows 7 and I presume Windows Vista don’t like DBPro strings. From what I’ve read the problem was double NULL terminated strings and not filling the rest of SHFILEOPSTRUCT struct with NULL values. Attached is the new plug-in with source. I have tested this on both systems; it appears to function as expected.
Ben_UK78
15
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 12th Jan 2012 04:07
Ah, fantastic. Worked like a charm. I recommend that plugin.

For anyone interested the windows shell32 code is supplied below.
It is a pain though. Testing it it will work in some folders and not in others. It might be being picky about double null termination and so working some of the time and not others, but I think it is more down to security - or at least giving the program administrator access would work in many folders tested, but not all.

For ease I recommend the plug-in above.

WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 12th Jan 2012 04:24 Edited at: 12th Jan 2012 04:25
I was thinking this was one of those things DBPro's DLL commands wouldn’t be able to handle, but you did it.

Good Job.

Login to post a reply

Server time is: 2026-07-09 20:54:49
Your offset time is: 2026-07-09 20:54:49