How to COPY and MOVE OS (LINUX) directories using C++ and IOStreams

  • Follow


How do I develop C++ code (maybe using (partially) IOStreams) to
physically 1) move a directory from one path in the filesytem to
another and 2) copy a directory from path in the filesystem to another?

I know how to copy files and move files, but directories are tougher. I
also need to pass a flag as a parameter which gives the option to copy
the directory recursively (assuming the parameter directory has
sub-entries (files and more directories) - else it becomes a no-op if
there are no more directories to descend.

class DirectoryHandler
{
  public:
  //ctor and dtor omiited for obvious reasons (brevity)

  int moveDirectory (const std::string& from, const std::string& to);
  int copyDirectory (const std::string& from, const std::string& to);

};

Thanks for any help


Tom Wallick


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply tomwallick (2) 3/1/2006 11:20:48 AM

tomwallick@yahoo.com wrote:
> How do I develop C++ code (maybe using (partially) IOStreams)
> to physically 1) move a directory from one path in the
> filesytem to another and 2) copy a directory from path in the
> filesystem to another?

> I know how to copy files and move files, but directories are
> tougher. I also need to pass a flag as a parameter which gives
> the option to copy the directory recursively (assuming the
> parameter directory has sub-entries (files and more
> directories) - else it becomes a no-op if class
> DirectoryHandler
> {
>   public:
>   //ctor and dtor omiited for obvious reasons (brevity)

>   int moveDirectory (const std::string& from, const std::string& to);
>   int copyDirectory (const std::string& from, const std::string& to);
> };

Standard C++ has no concept of directories, so there is
obviously no immediate support for this sort of thing.  In fact,
the solution I'd normally adopt is system(); the argument is
very system dependant, but then, any other solution would be as
well.

--
James Kanze                                           GABI Software
Conseils en informatique orient�e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply kanze 3/1/2006 4:55:19 PM


1 Replies
1169 Views

(page loaded in 0.058 seconds)

Similiar Articles:













7/20/2012 3:37:33 PM


Reply: