how to remove the file to trash? Topic is solved
-
- Experienced Solver
- Posts: 86
- Joined: Wed Apr 18, 2007 6:10 am
- Location: Shanghai China
how to remove the file to trash?
Hi, guys!
Is there a way to remove the file to trash?(Windows && MacOS)
Waiting for your reply.....
Is there a way to remove the file to trash?(Windows && MacOS)
Waiting for your reply.....
-
- Experienced Solver
- Posts: 86
- Joined: Wed Apr 18, 2007 6:10 am
- Location: Shanghai China
Thanks for your reply!ninja9578 wrote:I'm almost certain that both platforms simply have a folder for their trash. Simply move the file into the folder. It's in a weird place in Windows, I can get you the path if you'd like.
On OSX it's ~/.Trash
Is the same folder in windowsXP, windows vista and windows 7?ninja9578 wrote: It's in a weird place in Windows, I can get you the path if you'd like.
I am looking forward to know where is the place,and how to get it.
-
- wxWorld Domination!
- Posts: 1059
- Joined: Sun Dec 30, 2007 6:40 pm
- Location: Canada
Hi,
Here's some code I found a while ago from here (see figure 3): http://msdn.microsoft.com/en-us/magazine/bb985590.aspx
It will move files to the recycle bin on windows if the FOF_ALLOWUNDO flag is set.
RecycleFile.h
RecycleFile.cpp
To use it:
Hope that helps,
Jim
Here's some code I found a while ago from here (see figure 3): http://msdn.microsoft.com/en-us/magazine/bb985590.aspx
It will move files to the recycle bin on windows if the FOF_ALLOWUNDO flag is set.
RecycleFile.h
Code: Select all
////////////////////////////////////////////////////////////////
// MSDN April 2001
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 6.0. Runs on Windows 98 and probably Windows
// 2000 too.
//
#include <shellapi.h>
//////////////////
// CRecycleFile sends a file to the Recycle Bin.
// Note derived from SHFILEOPSTRUCT.
//
class CRecycleFile : public SHFILEOPSTRUCT {
protected:
public:
CRecycleFile();
~CRecycleFile() { }
int Recycle(LPCTSTR pszPath, BOOL bDelete=FALSE);
};
Code: Select all
////////////////////////////////////////////////////////////////
// MSDN ? April 2001
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 6.0. Runs on Windows 98 and probably Windows
// 2000 too.
//
#include <windows.h>
#include <tchar.h>
#include "RecycleFile.h"
//////////////////
// Constructor initializes SHFILEOPSTRUCT with reasonable
// defaults. You can override if you like. Go ahead, make my day.
//
CRecycleFile::CRecycleFile()
{
memset((SHFILEOPSTRUCT*)this,0,sizeof(SHFILEOPSTRUCT));
fFlags |= FOF_SILENT; // don't report progress
fFlags |= FOF_NOERRORUI; // don't report errors
fFlags |= FOF_NOCONFIRMATION; // don't confirm delete
}
//////////////////
// Send a file to the recycle bin. Args:
// - full pathname of file.
// - bDelete: if TRUE, really delete file (no recycle bin)
//
int CRecycleFile::Recycle(const char * pszPath, bool bDelete)
{
// Copy pathname to double-NULL-terminated string.
//
TCHAR buf[_MAX_PATH + 1]; // allow one more character
strcpy(buf,pszPath);
buf[strlen(buf)+1]=0; // need two NULLs at end
// _tcscpy(buf, pszPath); // copy caller's path name
// buf[_tcslen(buf)+1]=0; // need two NULLs at end
// Set SHFILEOPSTRUCT params for delete operation
//
wFunc = FO_DELETE; // REQUIRED: delete operation
pFrom = buf; // REQUIRED: which file(s)
pTo = NULL; // MUST be NULL
if (bDelete) { // if delete requested..
fFlags &= ~FOF_ALLOWUNDO; // ..don't use Recycle Bin
} else { // otherwise..
fFlags |= FOF_ALLOWUNDO; // ..send to Recycle Bin
}
return SHFileOperation(this); // do it!
}
Code: Select all
wxString fileToRecycle;
CRecycleFile x;
x.Recycle(fileToRecycle.c_str());
Jim
OS: Vista SP1, wxWidgets 2.8.7.
-
- Experienced Solver
- Posts: 86
- Joined: Wed Apr 18, 2007 6:10 am
- Location: Shanghai China
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: how to remove the file to trash?
Is this still the same on Windows 10?
Re: how to remove the file to trash?
The api still exists under Windows 10 and is even used by wxFileName::Rmdir
https://github.com/wxWidgets/wxWidgets/ ... .cpp#L1312
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: how to remove the file to trash?
perfect, thanx!
Re: how to remove the file to trash?
Hi,
The pull request PB referenced takes care of all 3 major platforms.
Give it a shot and see what happens.
Thank you.
The pull request PB referenced takes care of all 3 major platforms.
Give it a shot and see what happens.
Thank you.
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: how to remove the file to trash?
thanx, I only need it for windows but hope it will be part of the next regular release. Very important function imho. I copy and pasted the msw part.
Re: how to remove the file to trash?
Hi,
As an author I hope so too...
Thank you.
As an author I hope so too...
Thank you.