microsoft / microsoft/STL

<filesystem>: create_directory vs create_directories return codes

Open
#736 34 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

filesystem LWG issue needed
Dominant language
C++
Stars
11.2k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

When you have path with trailing backslash the return codes of std::filesystem::create_directories and std::filesystem::create_directory for the same path are different.
My problem is that return code are

  • different on msvc between <experimental/filesystem> and <filesystem>
  • different between msvc, clang and gcc

is someone right or is it implementation defined ?

#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
#include <filesystem>
#include <iostream>

int main()
{
	using std::cout;
	using std::endl;

	std::filesystem::remove("test1\\");
	std::filesystem::remove("test2\\");
	std::filesystem::remove("test3\\");
	std::filesystem::remove("test4\\");
	cout << "std::filesystem" <<endl;
	cout <<  std::filesystem::create_directory("test1\\")<< "\t:create_directory" << endl;
	cout <<  std::filesystem::create_directories("test2\\") << "\t:create_directories" << endl;
	cout << "std::experimental::filesystem" << endl;
	cout <<  std::experimental::filesystem::create_directory("test3\\") << "\t:create_directory" << endl;
	cout <<  std::experimental::filesystem::create_directories("test4\\") << "\t:create_directories" << endl;
}

this code will output

std::filesystem
1       :create_directory
0       :create_directories
std::experimental::filesystem
1       :create_directory
1       :create_directories

code to check on other compilers wandbox link

clang output for test/

std::filesystem
1	:create_directory
0	:create_directories

gcc output for test/

std::filesystem
1	:create_directory
1	:create_directories

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the trailing-backslash example in the issue and compare create_directory with create_directories across std::filesystem and std::experimental::filesystem, using the linked Wandbox example for the compiler comparison. Check the C++ filesystem specification to determine the required return values and whether the observed differences are conforming; done means the behavior is explained and any needed STL change is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.