I just finished polishing a class that will simplify the use of filesystems.
It uses BOOST library, and I know what you're going to say, but hear me out. No member of the class emplements a boost function, variable type, or namespace of any kind. All boost operations are performed in seperate functions.
so, fsys_class::copy
the function that uses boost: int copy_sup(), meaning copy supliment.
I've clocked it, and it uses (at max) 500Kb of memory (which is better than the 2000Kb of the previous class). At minimum it runs with around 400Kb. This is about as much as my programs that don't use classes (i wrote those a long while back, but have since learned a lot).
I've also looked at the recursive directory iterator's memory efficiency, and it is quite astonishing how efficient it is when seperated from the class.
The class also has an option: use the system() command. Whilest insecure, it does provide an extra, fool-proof way to execute an action. Because it is insecure, System() is only used if a bool in the class is set to true (default is false), and even then it is used as a last resort, and all else fails.
fsys_class.cpp:
http://pastebin.com/2wJgdFWC
fsys_class.h:
http://pastebin.com/RXnzyeDS
Tell me what you think.
*****************************************************************************
Notes:
The goal was to simplify file/folder operations, while maintaining efficiency, as well as assuring no-fail method.
I also wanted to make it easy t treat paths more like objects, as though your dragging and droping the files/folders.
so, for example:
1 2
|
fsys_class p = "C:\myfolder";
p.move_to("C:\program files");
|
so, now myfolder is under program files.
I tried to make it feel a lot more natural.
When you move, copy, or create a path (create only for folders) it will do so under
fsys_class::path
.
Any path can be used for copy, move, rename, and del. Create can only be done for folders.
If an error occurs during this process, and the folder/file copy, move, delete, rename fails to execute, it returns 1. It it succeeds, it returns 0.
Note: an error is only returned if the function could not carry out an action, but not if the function succeeeds, which means the error is not indicative of whether or not the copy/del/create/rename/move actually modified the file in any way. I may add that later on (i am wrapped up in college right now...)
I also added is_file and is_folder, which check for the existence of the path as a file, or as a folder.
In the class, there is a private variable: fsys_class::path. This variable represents the path the class is 'equal' to. It's default is the current path, returned by the boost function:
current_path()
.
There are also 2 functiosn that retrieve vaules from the private variable fsys_class::path: fsys_class::gpath(), and fsys_class::gilename. Because the path can be modified by invoking the public constructors, the variable is not public.
reasons for this: 1. Modification should not happen to the variable, but to the class
2. This is basic information retrieval. Items I've needed to have are the filename and the full path, hence the functions.
sub_stuff returns a vector of the strings that represent the paths under the current path, if the path is a folder.
*****************************************************************************
I think that covers everything. Have fun, and tell me what you think.
Also, this is for Windows OS.