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

FreeBSD Manual Pages

  
 
  

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

NAME
       std::filesystem::directory_entry::path -	std::filesystem::directory_en-
       try::path

Synopsis
	  const	 std::filesystem::path&	 path()	 const	noexcept;	(since
       C++17)
	  operator const std::filesystem::path&	 ()  const  noexcept;	(since
       C++17)

	  Returns the full path	the directory entry refers to.

Parameters
	  (none)

Return value
	  The full path	the directory entry refers to.

Example
       // Run this code

	#include <filesystem>
	#include <fstream>
	#include <iostream>

	namespace fs = std::filesystem;

	std::string get_stem(const fs::path& p)	{ return p.stem().string(); }
	void create_file(const fs::path& p) { std::ofstream o{p}; }

	int main()
	{
	    const fs::path dir{"tmp_dir"};
	    fs::create_directory(dir);
	    create_file(dir / "one");
	    create_file(dir / "two");
	    create_file(dir / "three");

	    for	(const auto& file : fs::directory_iterator(dir))
	    {
		// Explicit conversion
		std::cout << get_stem(file.path()) << '\n';

		// Implicit conversion
		std::cout << get_stem(file) << '\n';
	    }

	    fs::remove_all(dir);
	}

Possible output:
	two
	two
	one
	one
	three
	three

See also
	  path	  represents a path
	  (C++17) (class)

http://cppreference.com		  2024.06.10	  std::filesy...entry::path(3)

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

home | help