Skip to content

Exception in Directory.CreateDirectory when folder name ends with whitespace #23292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cpaul06 opened this issue Aug 22, 2017 · 2 comments
Closed
Assignees
Milestone

Comments

@cpaul06
Copy link

cpaul06 commented Aug 22, 2017

I'm getting inconsistent results when calling Directory.CreateDirectory in a .NETCoreApp 1.0 and 2.0 compared to .NETFramework 4.6.2.

If the folder ends with a whitespace but doesn't contain any whitespaces in the name:
Directory.CreateDirectory("c:\work\CreateDirectory\folder \inner") Directory.CreateDirectory("c:\work\CreateDirectory\ folder \inner")
will throw an exception:
at System.IO.Win32FileSystem.CreateDirectory(String fullPath)
at System.IO.Directory.CreateDirectory(String path)
at TrailingNETCore.Program.ValidateCreate(String path, String netFrameworkResult) in C:\source\TrailingWhiteSpace\TrailingWhiteSpace\TrailingNETCore\Program.cs:line 55

If the folder ends with a whitespace but contains whitespaces in the name:
Directory.CreateDirectory("c:\work\CreateDirectory\fold er \inner") Directory.CreateDirectory("c:\work\CreateDirectory\ fol der \inner")
will get different results than .NETFramework.

I attached an example program with various use cases and a comparison against .NETFramework
CreateDirectory.zip

@danmoseley
Copy link
Member

@nchikanov maybe this is something you'd be interested to investigate.

@JeremyKuhne
Copy link
Member

You cannot create a file or directory name that has trailing spaces or periods without using \\?\ at the beginning of the path. If you see that not working please reactivate. We explicitly do not want to support creating such paths without the syntax (e.g. adding it implicitly) as most apps can't handle it.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants