Question about deleting files and the trash

Question about deleting files and the trash

Postby driessen » Thu Dec 21, 2023 9:34 am

Hello,

If I delete a file in my application, of course, the file is gone.
But is there a possibility to delete file in a way that the deleted files can be restored from the trash?
Moving to $Recycle.Bin doesn't seem to be enough.

Thank you.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about deleting files and the trash

Postby Antonio Linares » Thu Dec 21, 2023 10:02 am

Dear Michel,

It seems as this code has to be used:
Code: Select all  Expand view
#include <stdio.h>
#include <windows.h>
#include <shellapi.h>

#define FO_DELETE 3 //Delete the files specified in pFrom.
#define FOF_ALLOWUNDO 0x40 //Preserve undo information, if possible.
#define FOF_NOCONFIRMATION 0x0010 //Do not ask the user to confirm selection.

typedef struct _SHFILEOPSTRUCT {
    HWND hwnd;
    UINT wFunc;
    LPCSTR pFrom;
    LPCSTR pTo;
    FILEOP_FLAGS fFlags;
    BOOL fAnyOperationsAborted;
    LPVOID hNameMappings;
    LPCSTR lpszProgressTitle;
} SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;

int main()
{
    SHFILEOPSTRUCT shf;
    shf.wFunc = FO_DELETE;
    shf.pFrom = "C:\\myfile.txt\0\0"; //File to delete
    shf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
    int result = SHFileOperation(&shf);
    if (result == 0)
    {
        printf("File deleted successfully.\n");
    }
    else
    {
        printf("Error: %d\n", result);
    }
    return 0;
}
 


So basically we have to use SHFileOperation() from FWH. We are going to build an example.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Question about deleting files and the trash

Postby Jimmy » Thu Dec 21, 2023 10:04 am

hi,

i´m not sure if there is a simple API Call. i use SHFile() Operation like Explorer

when set Flag FOF_ALLOWUNDO it will move deleted Files into Recycle-bin
have a look at https://forums.fivetechsupport.com/viewtopic.php?t=42417
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1584
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Question about deleting files and the trash

Postby driessen » Fri Dec 22, 2023 11:00 am

Hello Jimmy,

Deleting files by using ShFileOperation() works fine.
But the deleted files are not moved to the recycle bin yet.
So I need to set the flag FOF_ALLOWUNDO.
But how do I do that?

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about deleting files and the trash

Postby Antonio Linares » Fri Dec 22, 2023 11:05 am

Dear Michel,

It is the fifth parameter when you call SHFILEOPERATION()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Question about deleting files and the trash

Postby driessen » Fri Dec 22, 2023 11:18 am

Antonio,

I tried that, but there is no chance. No file in the recyle bin.

This is the code I use:
Code: Select all  Expand view
#define FO_DELETE         0x0003
#define FOF_ALLOWUNDO     0x0040

******************************************************************************

DeleteFile( DOCDOEL, ArcLst )  // DOCDOEL = file that has to be deleted
                               // ArcLst = Dialog Box

******************************************************************************

static function DeleteFile( cFileName , oDlg )

return SHFileOperation( oDlg:hWnd, FO_DELETE , cFileName + Chr( 0 ) ,, FOF_ALLOWUNDO )
Thanks a lot.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about deleting files and the trash

Postby Antonio Linares » Fri Dec 22, 2023 12:03 pm

Please do:

MsgInfo( DeleteFile( DOCDOEL, ArcLst ) )

and let us know what you get
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Question about deleting files and the trash

Postby driessen » Fri Dec 22, 2023 12:31 pm

Antonio,

The answer I get is : 0,00
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about deleting files and the trash

Postby Antonio Linares » Fri Dec 22, 2023 1:27 pm

https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shfileoperationa
Returns zero if successful; otherwise nonzero


so it seems as it is properly doing it...

I can't understand why they don't appear at the recycle bin
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Question about deleting files and the trash

Postby jll-fwh » Tue Dec 26, 2023 7:42 pm

Hello Secarse:

Have you tried moving it to the trash without deleting it? It disappears from the source folder and goes to the trash can.

greeting
Javier Lloris
javierllorisprogramador@gmail.com

Blogs personales:
Programación: https://javierlloris.blogspot.com/
Japonés: https://bitacorajaponesa.blogspot.com/
Cubos de Rubik: https://www.instagram.com/jllorisperson ... 2ybz0gmvul
Tengo una colección de unos 100 cubos de todo tipo de formas geométricas, todos resueltos, en instagram solo hay unos cuentos cubos.
Libreria: FWH/FWH1109 + Harbour 5.8.2 + Borland C++ 5.8.2
Editor de Recursos: PellecC
ADA, OURXDBU
S.O: XP / Win 7 /Win10
Blog: http://javierlloris.blogspot.com.es/
e-mail: javierllorisprogramador@gmail.com
User avatar
jll-fwh
 
Posts: 408
Joined: Fri Jan 29, 2010 8:14 pm
Location: Meliana - Valencia

Re: Question about deleting files and the trash

Postby driessen » Wed Jan 03, 2024 8:41 am

Javier,

Just moving to the trash, how do I do that?

To everyone, any idea what is going wrong?

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about deleting files and the trash

Postby Jimmy » Wed Jan 03, 2024 9:21 am

hi,

have you try my CODE Sample https://forums.fivetechsupport.com/viewtopic.php?t=42417
it work with Recylebin

Note : you must use "full-Path"
If pFrom is set to a file name without a full path, deleting the file with FO_DELETE does not move it to the Recycle Bin, even if the FOF_ALLOWUNDO flag is set. You must provide a full path to delete the file to the Recycle Bin.

https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-shfileopstructa
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1584
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 61 guests

cron