Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
koldo is currently offline  koldo
Messages: 3357
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 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 Smile )

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 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Honza

Thank you for reading the long post.

Smile 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.

Confused 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.

Confused 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.

Smile 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...

Confused 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 actual
bool 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 Sad

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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
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
Re: File/Folder deleting, Recycle Bin and Read only files [message #24221 is a reply to message #24216] Wed, 06 January 2010 11:51 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Mirek

I understand you but, how did you implement this ?

Did you do a new set of FileDelete() or DeleteFolderDeep() functions between others including Trash Bin support or RW permissions ?.

Best regards
Koldo


Best regards
Iñaki
Re: File/Folder deleting, Recycle Bin and Read only files [message #24236 is a reply to message #24221] Wed, 06 January 2010 21:59 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Wed, 06 January 2010 05:51

Hello Mirek

I understand you but, how did you implement this ?

Did you do a new set of FileDelete() or DeleteFolderDeep() functions between others including Trash Bin support or RW permissions ?.

Best regards
Koldo


I would just stay with FileDeletToBin...
Re: File/Folder deleting, Recycle Bin and Read only files [message #24241 is a reply to message #24236] Wed, 06 January 2010 23:10 Go to previous message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Quote:

I would just stay with FileDeletToBin...


Well Sad I will prepare extended versions with progress (Gate) support.

Best regards
Koldo


Best regards
Iñaki
Previous Topic: crash on exit from XmlView example
Next Topic: Little .ini reading request
Goto Forum:
  


Current Time: Sun Apr 28 11:39:48 CEST 2024

Total time taken to generate the page: 0.06338 seconds