Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::filesy...ion_pending(3)  C++ Standard Libary std::filesy...ion_pending(3)

NAME
       std::filesystem::recursive_directory_iterator::disable_recursion_pend-
       ing   -	 std::filesystem::recursive_directory_iterator::disable_recur-
       sion_pending

Synopsis
	  void disable_recursion_pending();  (since C++17)

	  Disables recursion to	the currently referred subdirectory, if	any.

	  The call modifies the	pending	recursion flag on the iterator in such
       a way that the
	  next time increment is called, the iterator will advance within  the
       current
	  directory  even  if it is currently referring	to a subdirectory that
       hasn't been
	  visited.

	  The status of	the pending recursion flag can be queried with	recur-
       sion_pending(),
	  which	 is  false after this call. It is reset	back to	true after in-
       crement,	and its
	  initial value	is also	true.

	  The behavior is undefined if *this is	the end	iterator.

Parameters
	  (none)

Return value
	  (none)

Exceptions
	  May throw implementation-defined exceptions.

Example
       // Run this code

	#include <cstdlib>
	#include <fstream>
	#include <iostream>
	#include <string>
	#include <filesystem>
	namespace fs = std::filesystem;

	int main()
	{
	    fs::current_path(fs::temp_directory_path());
	    fs::create_directories("sandbox/a/b/c");
	    fs::create_directories("sandbox/a/b/d/e");
	    std::ofstream("sandbox/a/b/file1.txt");
	    fs::create_symlink("a", "sandbox/syma");
	    std::system("tree sandbox");
	    for(auto i = fs::recursive_directory_iterator("sandbox");
		     i != fs::recursive_directory_iterator();
		   ++i ) {
		std::cout << std::string(i.depth()*2, '	') << *i;
		if(fs::is_symlink(i->symlink_status()))
		    std::cout << " -> "	<< fs::read_symlink(*i);
		std::cout << '\n';

		// do not descend into "b"
		if(i->path().filename()	== "b")
		    i.disable_recursion_pending();
	    }
	    fs::remove_all("sandbox");
	}

Possible output:
	sandbox
	 a
	    b
		c
		d
		   e
		file1.txt
	 syma -> a

	"sandbox/a"
	  "sandbox/a/b"
	"sandbox/syma" -> "a"

See also
	  recursion_pending checks whether the recursion is disabled  for  the
       current directory
			    (public member function)
	  increment	    advances to	the next entry
	  operator++	    (public member function)

http://cppreference.com		  2022.07.31	  std::filesy...ion_pending(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::filesystem::recursive_directory_iterator::disable_recursion_pending&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help