c++ - how to determine if file is contained by path with boost filesystem v3 -


How can I determine that the file is included in the path with the boost from file system v3.

I saw that there is one or more operator but it seems only literally

  • Take two complete paths of file and path
  • file Remove the last part of and see if this is equal to path (if it does)

    Is there a better way to do this?

    The following function should be determined that a file is anywhere within the given directory, either In the form of direct child or in some subdirectories.

      bool path_contains_file (path directory, path file) {// if the end ends with "/" and no root directory, then the last // component will be returned by iterators. " And will intervene / in the down / down / std :: par check, so we strip it before proceeding. If (dir.filename () == ".") Dir.remove_filename (); // We are also not interested in the name of the file. Emphasis (file.has_filename ()); File.remove_filename (); // If there is more component than the DIR file, then the file probably can not be in // dir. Auto dir_len = std :: distance (dir.begin (), dir.end ()); Auto file_len = std :: distance (file.begin (), file.end ()); If (dir_len & gt; file_len) false return; // This check stopped when accessing dir.end, so it is OK / file after // more directory components I will not be checked back std :: equal (dir.begin (), dir.end (), File.begin ()); }   

    If you just want to check whether the directory is an immediate parent of the file, then use it instead:

      bool path_directly_contains_file (path directory , Path file) {if (dir.filename () == ".") Dir.remove_filename (); Emphasis (file.has_filename ()); File.remove_filename (); Return dir == file; }   

    You may also be interested in the path for the operator == .

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -