Skip to content

Conversation

@rpetrusha
Copy link

@rpetrusha rpetrusha commented Sep 27, 2018

Documented Path.Join

The PR:

  • Documents the Path.Join overloads.
  • Documents the Path.GetFullPath(String,String) method.
  • Notes that Path.Combine is intended to be used with a base path and a relative path.
  • Adds links to the Windows file path format topic to each method with a string path parameter.

Related to dotnet/samples#328

Fixes #970
Fixes #1213
Fixes #877

//cc @JeremyKuhne

@rpetrusha rpetrusha added the 🚧 Hold for related PR Indicates a PR can only be merged when other related PRs are merged (see comments for links) label Sep 27, 2018
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
<param name="path">A relative path to concatenate to <see paramref="basePath" />.</param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some ## Examples for this overload as well? I think they really help illustrate how to use this method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key thing this is supposed to replace is depending on the current working directory.

Environment.CurrentDirectory = @"C:\temp";

// Current directory can change at any time by any thread in the process so this isn't deterministic.
string path = Path.GetFullPath(relativePath);

// Deterministic version (thread safe)
path = Path.GetFullPath(@"C:\temp", relativePath);

If you have any "relative" paths the new overload is the safe alternative. We also have a method for determining if the current directory will change paths when resolved/used: Path.IsPathFullyQualified

// If this returns true the current directory will not change the location the path points to
bool currentDirectorySafe = Path.IsPathFullyQualified(path);

MSBuild reading project files would be one concrete example of where this API should be used for thread safety. Any given path in a project file should be resolved (evaluated in their terms) using Path.GetFullPath(projectFilePath, itemPath).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A thing with this API that I really struggle with is that even you switched the parameters around in your write-up above....

path = Path.GetFullPath(@"C:\temp", relativePath);

But the signature is:

Path.GetFullPath (string path, string basePath)

@rpetrusha rpetrusha mentioned this pull request Dec 17, 2018
14 tasks
@mairaw
Copy link
Contributor

mairaw commented Jan 25, 2019

I can't still review this one because the samples PR hasn't been merged yet @rpetrusha.

@rpetrusha rpetrusha self-assigned this Feb 16, 2019
@rpetrusha rpetrusha added this to the February 2019 milestone Feb 16, 2019
@rpetrusha
Copy link
Author

@JeremyKuhne, @mairaw, and @BillWagner, this will be ready for review once dotnet/samples#328 merges.

@rpetrusha
Copy link
Author

Closing and reopening to begin new build after merge of dotnet/samples#328.

@rpetrusha rpetrusha closed this Feb 19, 2019
@rpetrusha rpetrusha reopened this Feb 19, 2019
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are great updates @rpetrusha

I had a few small suggestions, but this is ready to go. Once a build finishes, I'll approve.

[!code-csharp[System.IO.Path Members#13](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.Path Members/CS/pathmembers.cs#13)]
[!code-vb[System.IO.Path Members#13](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.Path Members/VB/pathmembers.vb#13)]
The following example displays <xref:System.IO.Path> field values on Windows and on Linux systems. Note that Windows supports either the forward slash (which is returned by the <xref:System.IO.Path.AltDirectorySeparatorChar> field) or the backslash (which is returned by the <xref:System.IO.Path.DirectorySeparatorChar> field) as path separator characters, while Linux supports only the forward slash.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend using "unix" instead of "Linux". That would cover MacOS as well.

This field can have the same value as <xref:System.IO.Path.DirectorySeparatorChar>. `AltDirectorySeparatorChar` and <xref:System.IO.Path.DirectorySeparatorChar> are both valid for separating directory levels in a path string.
The value of this field is a slash ('/') on the Windows, UNIX and Macintosh operating systems.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Macintosh is a UNIX system, so you can remove the specific callout to Mac.

- If you prefer to hard-code the directory separator character, you should use the forward slash (`/`) character. It is the only recognized directory separator character on Unix systems, as the output from the example shows, and is the <xref:System.IO.Path.AltDirectorySeparatorChar> on Windows.
- Use string concatenation to dynamically retrieve the path separator character at runtime and incorporate it into file system paths. For example,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: When I might persist path information, I use the AltSeparatorChar because it will be the / on both platforms. I only do that when the path info must be cross plat.

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM @rpetrusha

I ha a few small comments, but you can :shipit: when you are ready.

@rpetrusha rpetrusha merged commit c6cb4e8 into dotnet:master Feb 20, 2019
@rpetrusha rpetrusha deleted the path branch February 20, 2019 20:24
@mairaw mairaw mentioned this pull request Mar 12, 2019
@mairaw mairaw removed the 🚧 Hold for related PR Indicates a PR can only be merged when other related PRs are merged (see comments for links) label Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants