CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2011
    Posts
    19

    boost systemfile

    Hello all,
    I am trying to use the "path" and "copy_file" functions of boost filesystem in C++, and they work fine, except for cases when there are hidden files/subdirectories as below:

    for example, if I have the following directory pattern (Dir1 is the parent directory, and the rest are the child files/subdirectories):

    Dir1
    file1
    file2
    .file3
    subdir1
    .subdir2

    the following code will go through the Dir1, and it will fail in creating the "path" when it reaches ".file3" or ".subdir2"

    boost::filesystem:ath dir1_path(filepath.c_str());
    if( !boost::filesystem::exists(dir1_path) )
    cout<<"\nFile Not Found:" <<"\n";
    boost::filesystem::copy_file(filepath.c_str(), dir2_path);

    It is very common to have subdirectories inside directories that start with "." (in Windows platform these are the hidden files), any suggestion as far as how to copy a file that starts with character "." ?

    I would appreciate some help.

    thanks in advance,
    Rudy

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: boost systemfile

    It is very common to have subdirectories inside directories that start with "."
    No.

    (in Windows platform these are the hidden files)
    No, this is the case on Linux, not on Windows. On Windows a '.' is a the separator between the basename and the file extension.

    any suggestion as far as how to copy a file that starts with character "." ?
    Don't see why you can't copy them.

  3. #3
    Join Date
    Aug 2011
    Posts
    19

    Re: boost systemfile

    Let me rephrase my question to be more specific, and I wouldn't bother the reader by referring to Windows/UNIX platform.

    this is my question:
    I have the following directory pattern (Dir1 is the parent directory, and the rest are the child files/subdirectories):

    Dir1
    file1
    file2
    .file3
    subdir1
    .subdir2

    the following code will go through the Dir1, and it will fail in creating the "path" when it reaches ".file3" or ".subdir2"

    boost::filesystem:ath dir1_path(filepath.c_str());

    How should I create a path to a directory that (for example) has the following path?
    /root/my_docs/pgg/.file1

    filesystem:ath works just fine if I had to deal with (/root/my_docs/pgg/file1) instead of (/root/my_docs/pgg/.file1) !!!
    apparently when the file/directory starts with '.', I cannot get filesystem:ath to behave properly.

    please advise,
    thanks,
    Rudy

  4. #4
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: boost systemfile

    Quote Originally Posted by rudy01 View Post
    the following code will go through the Dir1, and it will fail in creating the "path" when it reaches ".file3" or ".subdir2"
    When you say "create the path", do you mean create an instance of boost::filesystem::path that is initialized to the path that ends with ".file3"?
    Are you getting an assertion somewhere, or a crash?
    Also please mention which version of boost you are using and which version of the Filesystem library (version 2 and 3 are maintained in parallel).
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  5. #5
    Join Date
    Aug 2011
    Posts
    19

    Re: boost systemfile

    I think I am using version 1.0

    // Use, modification, and distribution is subject to the Boost Software
    // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
    // at http://www.boost.org/LICENSE_1_0.txt)

    And this is the error that I am getting:

    terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
    what(): boost::filesystem:ath: invalid name ".sync.cpp.swp" in path: "src/.sync.cpp.swp"
    Abort

    can this be the issue?

    thanks,
    Rudy

  6. #6
    Join Date
    Aug 2011
    Posts
    19

    Re: boost systemfile

    just found out that I am using boost version 1.45, and gcc version 3.3.6

    /apps/boost/1.45.0/lib:/apps/gcc/4.3.5/lib

    when I tried to use higher version of gcc (e.g. 4.4.0, 4.5.1, 4.6.0), I am all getting errors regarding boost

    g++ -lboost_filesystem -Wno-deprecated -g src/sync.cpp -o obj/sync_dir

    In file included from /usr/include/boost/mpl/apply.hpp:23,
    from /usr/include/boost/iterator/iterator_facade.hpp:34,
    from /usr/include/boost/filesystem/path.hpp:16,
    from /usr/include/boost/filesystem/operations.hpp:18,
    from src/sync.cpp:17:
    /usr/include/boost/mpl/apply_wrap.hpp:81:31: error: missing binary operator before token "("
    /usr/include/boost/mpl/apply_wrap.hpp:173:31: error: missing binary operator before token "("
    In file included from /usr/include/boost/mpl/bind.hpp:27,
    from /usr/include/boost/mpl/lambda.hpp:18,
    from /usr/include/boost/mpl/apply.hpp:25,
    from /usr/include/boost/iterator/iterator_facade.hpp:34,
    from /usr/include/boost/filesystem/path.hpp:16,
    from /usr/include/boost/filesystem/operations.hpp:18,
    from src/sync.cpp:17:
    /usr/include/boost/mpl/apply_wrap.hpp:81:31: error: missing binary operator before token "("
    /usr/include/boost/mpl/apply_wrap.hpp:173:31: error: missing binary operator before token "("
    In file included from /usr/include/boost/mpl/lambda.hpp:18,
    from /usr/include/boost/mpl/apply.hpp:25,
    from /usr/include/boost/iterator/iterator_facade.hpp:34,
    from /usr/include/boost/filesystem/path.hpp:16,
    from /usr/include/boost/filesystem/operations.hpp:18,
    from src/sync.cpp:17:
    /usr/include/boost/mpl/bind.hpp:364:31: error: missing binary operator before token "("

    please help,
    thanks,
    Rudy

  7. #7
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: boost systemfile

    Quote Originally Posted by rudy01 View Post
    I think I am using version 1.0
    That's the version of the license.
    Quote Originally Posted by rudy01 View Post
    And this is the error that I am getting:

    terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
    what(): boost::filesystem:ath: invalid name ".sync.cpp.swp" in path: "src/.sync.cpp.swp"
    Abort

    can this be the issue?
    That means an exception is being thrown from the boost library, but it is not caught by your code. Find out from which line in your code the exception is being thrown by stepping through your program with the debugger.
    Quote Originally Posted by rudy01 View Post
    just found out that I am using boost version 1.45, and gcc version 3.3.6
    Version 1.45 defaults to version 3 of Boost.Filesystem. I'm using version 1.44 (version 3 of Boost.Filesystem) in VS2008 and the following program does not throw an exception.
    Code:
    #define BOOST_FILESYSTEM_VERSION 3
    #include <boost/filesystem/path.hpp>
    #include <iostream>
    
    int main()
    {
    	try {
    		boost::filesystem::path p("src/.sync.cpp.swp");
    	}
    	catch (const std::exception& e) {
    		std::cout << "Exception: " << e.what() << std::endl;
    	}
    }
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured