internal PhysicalStoragePath(string path, FileSystem fileSystem) : base(fileSystem, path) { Debug.Assert( ReferenceEquals(fileSystem.PathInformation, PhysicalPathHelper.PhysicalPathInformation), $"When using the PhysicalStoragePath, your file system should be using the corresponding " + $"{nameof(PhysicalPathHelper.PhysicalPathInformation)}." ); var fullPath = GetFullPathOrThrow(path); var rootPath = Path.GetPathRoot(path); var pathWithoutTrailingSeparator = PathPolyfills.TrimEndingDirectorySeparator(path); var directoryPath = Path.GetDirectoryName(pathWithoutTrailingSeparator); var name = Path.GetFileName(pathWithoutTrailingSeparator); var nameWithoutExtension = GetNameWithoutExtension(name); var extension = PhysicalPathHelper.GetExtensionWithoutTrailingExtensionSeparator(pathWithoutTrailingSeparator); var isPathFullyQualified = PathPolyfills.IsPathFullyQualified(path); Kind = isPathFullyQualified ? PathKind.Absolute : PathKind.Relative; Name = name; NameWithoutExtension = nameWithoutExtension; Extension = string.IsNullOrEmpty(extension) ? null : extension; _rootLazy = new Lazy <StoragePath?>( () => string.IsNullOrEmpty(rootPath) ? null : fileSystem.GetPath(rootPath) ); _parentLazy = new Lazy <StoragePath?>( () => string.IsNullOrEmpty(directoryPath) ? null : fileSystem.GetPath(directoryPath) ); _fullPathLazy = new Lazy <StoragePath>( () => fileSystem.GetPath(fullPath) );
public static void CopyDirectory(string source, string destination, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); var directories = Directory.GetDirectories(source); var files = Directory.GetFiles(source); Directory.CreateDirectory(destination); foreach (var dirSrc in directories) { cancellationToken.ThrowIfCancellationRequested(); var dirDest = PathPolyfills.Join(destination, Path.GetFileName(dirSrc)); CopyDirectory(dirSrc, dirDest, cancellationToken); } foreach (var fileSrc in files) { cancellationToken.ThrowIfCancellationRequested(); var fileDest = PathPolyfills.Join(destination, Path.GetFileName(fileSrc)); File.Copy(fileSrc, fileDest); } }