Boost Filesystem copy_file()
-
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 :)
-
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 :)
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?
-
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?
-
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!