Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Boost Filesystem copy_file()

Boost Filesystem copy_file()

Scheduled Pinned Locked Moved C / C++ / MFC
help
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RobNO
    wrote on last edited by
    #1

    Hey everyone! I am wondering why this code keeps throwing me exceptions and how I can fix this problem.

    #include <boost/filesystem.hpp>
    namespace bf = boost::filesystem;
    #include <string>
    #include <iostream>
    using namespace std;
    string e_string = "Error";
    int main()
    {
    string fileName = "C:\\Downloads\\Hits from the Bow\\01 This Time You're Gonna Get it Dir.mp3";
    string destination = "c:\\downloads\\test" ;
    bf::path fileCopied(fileName);
    bf::path fileCopiedDestination (destination);
    if (!bf::exists(fileCopied) )
    {
    cerr << e_string;
    }
    if (!bf::exists(fileCopiedDestination))
    {
    cerr << e_string;
    }
    try
    {
    bf::copy_file(fileCopied,fileCopiedDestination);
    }
    catch(std::exception e)
    {
    cout << e.what();
    }
    }

    Thanks for your time :)

    R 1 Reply Last reply
    0
    • R RobNO

      Hey everyone! I am wondering why this code keeps throwing me exceptions and how I can fix this problem.

      #include <boost/filesystem.hpp>
      namespace bf = boost::filesystem;
      #include <string>
      #include <iostream>
      using namespace std;
      string e_string = "Error";
      int main()
      {
      string fileName = "C:\\Downloads\\Hits from the Bow\\01 This Time You're Gonna Get it Dir.mp3";
      string destination = "c:\\downloads\\test" ;
      bf::path fileCopied(fileName);
      bf::path fileCopiedDestination (destination);
      if (!bf::exists(fileCopied) )
      {
      cerr << e_string;
      }
      if (!bf::exists(fileCopiedDestination))
      {
      cerr << e_string;
      }
      try
      {
      bf::copy_file(fileCopied,fileCopiedDestination);
      }
      catch(std::exception e)
      {
      cout << e.what();
      }
      }

      Thanks for your time :)

      R Offline
      R Offline
      RobNO
      wrote on last edited by
      #2

      Okay So I found out away for the copy_file() function to work

      #include <boost/filesystem.hpp>
      namespace bf = boost::filesystem;
      #include <string>
      #include <iostream>
      using namespace std;
      string e_string = "Error";
      int main()
      {
      string fileName = "C:/Downloads/Hits from the Bow/01 This Time You're Gonna Get it Dir.mp3";
      string destination = "c:/downloads/test/this is why it wouldnt work.mp3" ; //right here
      bf::path fileCopied(fileName);
      bf::path fileCopiedDestination (destination);
      if (!bf::exists(fileCopied) )
      {
      cerr << e_string;
      }
      if (!bf::exists(fileCopiedDestination))
      {
      cerr << e_string;
      }
      try
      {
      bf::copy_file(fileName,destination);

      }
      catch(std::exception e)
      {
      	cout << e.what();
      }
      

      }

      I did not specify the file name. But I do not think this actually solves the full problem because An exception is still being thrown, any ideas at all?

      R 1 Reply Last reply
      0
      • R RobNO

        Okay So I found out away for the copy_file() function to work

        #include <boost/filesystem.hpp>
        namespace bf = boost::filesystem;
        #include <string>
        #include <iostream>
        using namespace std;
        string e_string = "Error";
        int main()
        {
        string fileName = "C:/Downloads/Hits from the Bow/01 This Time You're Gonna Get it Dir.mp3";
        string destination = "c:/downloads/test/this is why it wouldnt work.mp3" ; //right here
        bf::path fileCopied(fileName);
        bf::path fileCopiedDestination (destination);
        if (!bf::exists(fileCopied) )
        {
        cerr << e_string;
        }
        if (!bf::exists(fileCopiedDestination))
        {
        cerr << e_string;
        }
        try
        {
        bf::copy_file(fileName,destination);

        }
        catch(std::exception e)
        {
        	cout << e.what();
        }
        

        }

        I did not specify the file name. But I do not think this actually solves the full problem because An exception is still being thrown, any ideas at all?

        R Offline
        R Offline
        RobNO
        wrote on last edited by
        #3

        sorry for the spam.. I think i figured it out. The destination file also dosnt exists in the first place. Thanks anyways.. If any one has any comments i would be happy to hear them!

        L 1 Reply Last reply
        0
        • R RobNO

          sorry for the spam.. I think i figured it out. The destination file also dosnt exists in the first place. Thanks anyways.. If any one has any comments i would be happy to hear them!

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Suggestion: Your original question states that you get an exception, but you did not post the message raised by the exception. People reading your question cannot guess what that exception might be.

          It's time for a new signature.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups