Skip to content
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

(Error .Net Core 5) "Directory.GetDirectories("D:")" returns not existingDirectory #68503

Closed
vsfeedback opened this issue Apr 25, 2022 · 10 comments · Fixed by #94587
Closed

(Error .Net Core 5) "Directory.GetDirectories("D:")" returns not existingDirectory #68503

vsfeedback opened this issue Apr 25, 2022 · 10 comments · Fixed by #94587

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


String[] dirSSS = Directory.GetDirectories("D:");
dirSSS[0];             // Output:  "D:\ref" (without quotes) <-- no this directory on disk "D:"!
Environment.Version;   // "5.0.13" (Net Core)
Environment.OSVersion; // "Microsoft Windows NT 6.3.9600.0"
                       // VS (Russian):
                       //    Microsoft Visual Studio Professional&nbsp;2019
                       //    Версия 16.11.9

There is another theme with this error, but it closed:
https://developercommunity2.visualstudio.com/t/DirectoryGetDirectoriesdrive-return-a/175411?entry=suggestion&space=8&preview2=true


Original Comments

Feedback Bot on 3/21/2022, 00:32 AM:

(private comment, text removed)

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.IO untriaged New issue has not been triaged by the area owner labels Apr 25, 2022
@ghost
Copy link

ghost commented Apr 25, 2022

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

This issue has been moved from a ticket on Developer Community.


String[] dirSSS = Directory.GetDirectories("D:");
dirSSS[0];             // Output:  "D:\ref" (without quotes) <-- no this directory on disk "D:"!
Environment.Version;   // "5.0.13" (Net Core)
Environment.OSVersion; // "Microsoft Windows NT 6.3.9600.0"
                       // VS (Russian):
                       //    Microsoft Visual Studio Professional&nbsp;2019
                       //    Версия 16.11.9

There is another theme with this error, but it closed:
https://developercommunity2.visualstudio.com/t/DirectoryGetDirectoriesdrive-return-a/175411?entry=suggestion&space=8&preview2=true


Original Comments

Feedback Bot on 3/21/2022, 00:32 AM:

(private comment, text removed)

Author: vsfeedback
Assignees: -
Labels:

area-System.IO, untriaged

Milestone: -

@skyoxZ
Copy link
Contributor

skyoxZ commented Apr 27, 2022

I tested the code below and got an amazing result:

using System;
using System.IO;

for(int i = 0;i < 20; i++)
{
    string s = (char)('A' + i) + ":";
    Console.WriteLine(s + " -> " + Path.GetFullPath(s));
}

Output:

A: -> A:\
B: -> B:\
C: -> C:\WINDOWS\System32
D: -> D:\vs projects\ConsoleApp1\ConsoleApp1\bin\Debug\net6.0
E: -> E:\
F: -> F:\
G: -> G:\
...

@svick
Copy link
Contributor

svick commented Apr 27, 2022

This is called a drive relative path and it's why the backslash in D:\ is important. For more details, see the article on Windows paths.

@skyoxZ
Copy link
Contributor

skyoxZ commented Apr 27, 2022

This is called a drive relative path and it's why the backslash in D:\ is important. For more details, see the article on Windows paths.

I read the article but still don't understand what happened exactly. And I think the behavior in this issue is definitely unexpected.

Update: I understand my case now and believe D:\ref is a bug.

@svick
Copy link
Contributor

svick commented May 2, 2022

I understand my case now and believe D:\ref is a bug.

I think you're right. Returning the ref directory is correct. But returning it as D:\ref is incorrect. Instead, I think it should be returned as D:ref in this case.

@jozkee
Copy link
Member

jozkee commented May 3, 2022

dirSSS[0]; // Output: "D:\ref"
Environment.Version; // "5.0.13" (Net Core)
Environment.OSVersion; // "Microsoft Windows NT 6.3.9600.0"

I wonder if this bug is specific to Windows 8.1, in such case it would probably be tied to the Windows API, not to .NET.
I couldn't repro it on windows 10.

Directory.GetDirectories("C:") does yield the right results for me (folders of the current working directory).

@jozkee jozkee closed this as completed May 3, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label May 3, 2022
@jozkee
Copy link
Member

jozkee commented May 3, 2022

@skyoxZ linking issue related to your comments: #63892.

@skyoxZ
Copy link
Contributor

skyoxZ commented May 3, 2022

@jozkee I did repro the D:\ref issue on my Win 11.
May give more info about 3 days later (I'm on holiday).

@jozkee jozkee reopened this May 3, 2022
@jozkee jozkee added this to the Future milestone May 3, 2022
@jozkee
Copy link
Member

jozkee commented May 4, 2022

@skyoxZ yes please, could you please also add Console.WriteLine(Environment.CurrentDirectory); to your repro. I want to discard that the cwd is indeed different to what's being used in GetDirectories.

@skyoxZ
Copy link
Contributor

skyoxZ commented May 5, 2022

@jozkee Please try the code below:

string foo = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "foo");
string bar = Path.Combine(foo, "bar");
Directory.CreateDirectory(bar);
Environment.CurrentDirectory = foo;
string root = foo.Remove(2);
string[] ss = Directory.GetDirectories(root);
Console.WriteLine("-- " + root);
foreach(string s in ss)
{
    Console.WriteLine(s);
}

.NET Framework 4.8 got correct result:

-- D:
D:bar

however, .NET 6.0 got the result below:

-- D:
D:\bar

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Nov 9, 2023
@jozkee jozkee modified the milestones: Future, 9.0.0 Nov 10, 2023
jozkee added a commit that referenced this issue Nov 27, 2023
Fixes #68503

On netfx we were concatenating user directories ending with volume separator `:` instead of joining with a path separator `\`. That is not the case in .NET [core]. This change brings that back as it is incorrect to join paths like "C:" with a separator in between the enumerated entries as the meaning of "relative to drive's CWD" gets lost.
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Nov 27, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants