|
|
Home » U++ Library support » U++ Core » File/Folder deleting, Recycle Bin and Read only files
File/Folder deleting, Recycle Bin and Read only files [message #24203] |
Tue, 05 January 2010 10:02  |
 |
koldo
Messages: 3432 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
Presently we have this basic functions to delete files and folders:
bool FileDelete(const char *filename)
bool DirectoryDelete(const char *dirname)
They delete forever a file/folder if it is not read-only (and of course if it is available).
It would be great if they would manage as transparently as possible the Recycle Bin and the Read-Only files.
Some possible options would be:
1.- To add to this functions new parameters. For example:
bool FileDelete(const char *filename, bool recycleBin = false, bool delReadOnly = false)
bool DirectoryDelete(const char *dirname, bool recycleBin = false, bool delReadOnly = false)
or
enum DeleteFlags {DEL_FOREVER = 0, DEL_RECYCLE = 1, NOT_DEL_READONLY = 0, DEL_READONLY = 2};
bool FileDelete(const char *filename, int flags = 0)
bool DirectoryDelete(const char *dirname, int flags = 0)
2.- To add functions to handle this:
void SetDeleteToRecycleBin(bool val = false);
void SetDeleteReadOnly(bool val = false);
or
enum DeleteFlags {DEL_FOREVER = 0, DEL_RECYCLE = 1, NOT_DEL_READONLY = 0, DEL_READONLY = 2};
void SetDeleteFlags(bool val = false);
What do you think about it ?
Best regards
Koldo
Best regards
Iñaki
|
|
|
Re: File/Folder deleting, Recycle Bin and Read only files [message #24206 is a reply to message #24203] |
Tue, 05 January 2010 13:56   |
|
koldo wrote on Tue, 05 January 2010 10:02 | It would be great if they would manage as transparently as possible the Recycle Bin and the Read-Only files.
|
Hi Koldo,
It's interesting idea, but it's definitely not multiplatform. On Linux filesystems read-only usually means you simply don't have the permission to delete the file. Also recycle bin might not be available and even when it is then its behaviour and implementation differs in each desktop environment.
On windows, it might be useful. If I remember correctly, winXP show a dialog if you really wan't to delete read-only or system file, not sure about vista or win7 (but I heard their permissions system are better now )
Thinking about it, another way to achieve this would be to implement function that manages file attributes. (Or is there something like that in upp already?) Then you could just delete the read-only flag and delete it. For recycle bin I would suggest special function to. It feels "cleaner" to me to add#ifdef PLATFORM_WIN32
SetAttributes(int Attr);
MoveToRecycleBin(const char* File);
#endif instead of changing the existing functions in win32 specific way...
Best regards
Honza
|
|
|
Re: File/Folder deleting, Recycle Bin and Read only files [message #24207 is a reply to message #24206] |
Tue, 05 January 2010 15:11   |
 |
koldo
Messages: 3432 Registered: August 2008
|
Senior Veteran |
|
|
Hello Honza
Thank you for reading the long post.
Some comments:
Quote: | It's interesting idea, but it's definitely not multiplatform. On Linux filesystems read-only usually means you simply don't have the permission to delete the file.
|
If my user have the permission, it can change the file attributes using chmod() in Linux.
See bool FileSetReadOnly(String fileName, bool readOnly) implementation in Functions4U Bazaar package..
Quote: | Also recycle bin might not be available
|
As far as I know Gnome and Kde desktops have Recycle Bin (or Trash Bin). At least in case of Gnome and Ubuntu derivatives, Trash Bin is located in a fixed folder.
See bool FileToTrashBin(const char *path) implementation in Functions4U Bazaar package.
Quote: | and even when it is then its behaviour and implementation differs in each desktop environment.
|
No problem, Upp packages have some internal #ifdef PLATFORM_POSIX and many other so that the final user does not have to worry about OS/Desktop particular behaviours.
Quote: | Thinking about it, another way to achieve this would be to implement function that manages file attributes. (Or is there something like that in upp already?) Then you could just delete the read-only flag and delete it. For recycle bin I would suggest special function to. It feels "cleaner" to me to add
#ifdef PLATFORM_WIN32
SetAttributes(int Attr);
MoveToRecycleBin(const char* File);
#endif
instead of changing the existing functions in win32 specific way...
|
These functions are already implemented in Functions4U Bazaar package as:
bool FileToTrashBin(const char *path);
int64 TrashBinGetCount();
bool TrashBinClear();
bool FileSetReadOnly(String fileName, bool readOnly);
They could be reimplemented, renamed and transfered to Core package... the problem is that derived functions would have to be changed like actualbool DeleteFolderDeep(const char *dir) ...
I would not like to have a
bool FileToTrashBinDeep(const char *dir)
SetAttributesDeep(String folder, int Attr)
and different version handling Trash Bin and Read permissions for the rest of functions that use FileDelete or DirectoryDelete
Best regards
Koldo
Best regards
Iñaki
|
|
|
Re: File/Folder deleting, Recycle Bin and Read only files [message #24216 is a reply to message #24203] |
Wed, 06 January 2010 07:49   |
 |
mirek
Messages: 14256 Registered: November 2005
|
Ultimate Member |
|
|
koldo wrote on Tue, 05 January 2010 04:02 | Hello all
Presently we have this basic functions to delete files and folders:
bool FileDelete(const char *filename)
bool DirectoryDelete(const char *dirname)
They delete forever a file/folder if it is not read-only (and of course if it is available).
It would be great if they would manage as transparently as possible the Recycle Bin and the Read-Only files.
Some possible options would be:
1.- To add to this functions new parameters. For example:
bool FileDelete(const char *filename, bool recycleBin = false, bool delReadOnly = false)
bool DirectoryDelete(const char *dirname, bool recycleBin = false, bool delReadOnly = false)
or
enum DeleteFlags {DEL_FOREVER = 0, DEL_RECYCLE = 1, NOT_DEL_READONLY = 0, DEL_READONLY = 2};
bool FileDelete(const char *filename, int flags = 0)
bool DirectoryDelete(const char *dirname, int flags = 0)
2.- To add functions to handle this:
void SetDeleteToRecycleBin(bool val = false);
void SetDeleteReadOnly(bool val = false);
or
enum DeleteFlags {DEL_FOREVER = 0, DEL_RECYCLE = 1, NOT_DEL_READONLY = 0, DEL_READONLY = 2};
void SetDeleteFlags(bool val = false);
What do you think about it ?
Best regards
Koldo
|
I do not think doing it this way is a good idea.
Path.h functions are meant to be base level API encapsulation. At these levels, OS has no notion abour recycle bin.
Recycle bin, OTOH, is a high level, basically OS shell function.
Mirek
|
|
|
|
|
|
Goto Forum:
Current Time: Wed Apr 30 05:08:30 CEST 2025
Total time taken to generate the page: 0.04299 seconds
|
|
|