_name = fileName ?? (PathInternal.IsRoot(fullPath.AsSpan()) ?
fullPath.AsSpan() :
- Path.GetFileName(PathInternal.TrimEndingDirectorySeparator(fullPath.AsSpan()))).ToString();
+ Path.GetFileName(Path.TrimEndingDirectorySeparator(fullPath.AsSpan()))).ToString();
FullPath = fullPath;
}
// FullPath might end in either "parent\child" or "parent\child\", and in either case we want
// the parent of child, not the child. Trim off an ending directory separator if there is one,
// but don't mangle the root.
- string parentName = Path.GetDirectoryName(PathInternal.IsRoot(FullPath.AsSpan()) ? FullPath : PathInternal.TrimEndingDirectorySeparator(FullPath));
+ string parentName = Path.GetDirectoryName(PathInternal.IsRoot(FullPath.AsSpan()) ? FullPath : Path.TrimEndingDirectorySeparator(FullPath));
return parentName != null ?
new DirectoryInfo(parentName, isNormalized: true) :
null;
string newPath = Path.GetFullPath(Path.Combine(FullPath, path));
- ReadOnlySpan<char> trimmedNewPath = PathInternal.TrimEndingDirectorySeparator(newPath.AsSpan());
- ReadOnlySpan<char> trimmedCurrentPath = PathInternal.TrimEndingDirectorySeparator(FullPath.AsSpan());
+ ReadOnlySpan<char> trimmedNewPath = Path.TrimEndingDirectorySeparator(newPath.AsSpan());
+ ReadOnlySpan<char> trimmedCurrentPath = Path.TrimEndingDirectorySeparator(FullPath.AsSpan());
// We want to make sure the requested directory is actually under the subdirectory.
if (trimmedNewPath.StartsWith(trimmedCurrentPath, PathInternal.StringComparison)
// didn't have a separator. Join() would handle it if we did trim it, not doing so is an optimization.
ReadOnlySpan<char> relativePath = Directory.Slice(RootDirectory.Length);
- if (PathInternal.EndsInDirectorySeparator(OriginalRootDirectory) && PathInternal.StartsWithDirectorySeparator(relativePath))
+ if (Path.EndsInDirectorySeparator(OriginalRootDirectory) && PathInternal.StartsWithDirectorySeparator(relativePath))
relativePath = relativePath.Slice(1);
return Path.Join(OriginalRootDirectory, relativePath, FileName);
public FileSystemEnumerator(string directory, EnumerationOptions options = null)
{
_originalRootDirectory = directory ?? throw new ArgumentNullException(nameof(directory));
- _rootDirectory = PathInternal.TrimEndingDirectorySeparator(Path.GetFullPath(directory));
+ _rootDirectory = Path.TrimEndingDirectorySeparator(Path.GetFullPath(directory));
_options = options ?? EnumerationOptions.Default;
// We need to initialize the directory handle up front to ensure
public FileSystemEnumerator(string directory, EnumerationOptions options = null)
{
_originalRootDirectory = directory ?? throw new ArgumentNullException(nameof(directory));
- _rootDirectory = PathInternal.TrimEndingDirectorySeparator(Path.GetFullPath(directory));
+ _rootDirectory = Path.TrimEndingDirectorySeparator(Path.GetFullPath(directory));
_options = options ?? EnumerationOptions.Default;
// We'll only suppress the media insertion prompt on the topmost directory as that is the
// storing those results separately. We only report failure if the initial
// lstat fails, as a broken symlink should still report info on exists, attributes, etc.
_isDirectory = false;
- path = PathInternal.TrimEndingDirectorySeparator(path);
+ path = Path.TrimEndingDirectorySeparator(path);
int result = Interop.Sys.LStat(path, out _fileStatus);
if (result < 0)
{
// our historical behavior (outside of File.Exists()), we need to trim.
//
// See http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11 for details.
- return FileExists(PathInternal.TrimEndingDirectorySeparator(fullPath), Interop.Sys.FileTypes.S_IFREG, out ignored);
+ return FileExists(Path.TrimEndingDirectorySeparator(fullPath), Interop.Sys.FileTypes.S_IFREG, out ignored);
}
private static bool FileExists(ReadOnlySpan<char> fullPath, int fileType, out Interop.ErrorInfo errorInfo)
// Input allows trailing separators in order to match Windows behavior
// Unix does not accept trailing separators, so must be trimmed
- if (!FileExists(PathInternal.TrimEndingDirectorySeparator(fullPath),
+ if (!FileExists(Path.TrimEndingDirectorySeparator(fullPath),
Interop.Sys.FileTypes.S_IFREG, out fileExistsError) &&
fileExistsError.Error == Interop.Error.ENOENT)
{
int length = fullPath.Length;
// We need to trim the trailing slash or the code will try to create 2 directories of the same name.
- if (length >= 2 && PathInternal.EndsInDirectorySeparator(fullPath))
+ if (length >= 2 && Path.EndsInDirectorySeparator(fullPath))
{
length--;
}
// This surfaces as a IOException, if we let it go beyond here it would
// give DirectoryNotFound.
- if (PathInternal.EndsInDirectorySeparator(sourceFullPath))
+ if (Path.EndsInDirectorySeparator(sourceFullPath))
throw new IOException(SR.Format(SR.IO_PathNotFound_Path, sourceFullPath));
// ... but it doesn't care if the destination has a trailing separator.
- destFullPath = PathInternal.TrimEndingDirectorySeparator(destFullPath);
+ destFullPath = Path.TrimEndingDirectorySeparator(destFullPath);
}
if (FileExists(destFullPath))
int length = fullPath.Length;
// We need to trim the trailing slash or the code will try to create 2 directories of the same name.
- if (length >= 2 && PathInternal.EndsInDirectorySeparator(fullPath.AsSpan()))
+ if (length >= 2 && Path.EndsInDirectorySeparator(fullPath.AsSpan()))
length--;
int lengthRoot = PathInternal.GetRootLength(fullPath.AsSpan());
int errorCode = Interop.Errors.ERROR_SUCCESS;
// Neither GetFileAttributes or FindFirstFile like trailing separators
- path = PathInternal.TrimEndingDirectorySeparator(path);
+ path = Path.TrimEndingDirectorySeparator(path);
using (DisableMediaInsertionPrompt.Create())
{
private static void GetFindData(string fullPath, ref Interop.Kernel32.WIN32_FIND_DATA findData)
{
- using (SafeFindHandle handle = Interop.Kernel32.FindFirstFile(PathInternal.TrimEndingDirectorySeparator(fullPath), ref findData))
+ using (SafeFindHandle handle = Interop.Kernel32.FindFirstFile(Path.TrimEndingDirectorySeparator(fullPath), ref findData))
{
if (handle.IsInvalid)
{
// being manipulated concurrently with these checks) is that we throw a
// FileNotFoundException instead of DirectoryNotFoundException.
- bool directoryError = !Directory.Exists(Path.GetDirectoryName(PathInternal.TrimEndingDirectorySeparator(path)));
+ bool directoryError = !Directory.Exists(Path.GetDirectoryName(Path.TrimEndingDirectorySeparator(path)));
throw Interop.GetExceptionForIoErrno(new Interop.ErrorInfo(Interop.Error.ENOENT), path, directoryError);
}