public bool IsChildOf(IDirectoryPath parentDirectory) { Debug.Assert(parentDirectory != null); var parentDirectoryString = parentDirectory.ToString(); // Don't accept equals pathString! var parentDirectoryStringLength = parentDirectoryString.Length; if (m_PathString.Length <= parentDirectoryStringLength) { return(false); } // Possible since at this point (m_PathString.Length > parentDirectoryStringLength) var c = m_PathString[parentDirectoryStringLength]; // Need to check that char at pos pathStringLength is a separator, // else @"D:/Foo bar" is considered as a child of @"D:/Foo". // Note that m_PathString is normalized in ctor, hence its separator(s) are DIR_SEPARATOR_CHAR. if (c != MiscHelpers.DIR_SEPARATOR_CHAR) { return(false); } string parentPathLowerCase = parentDirectory.ToString().ToLower(); string thisPathLowerCase = m_PathString.ToLower(); return(thisPathLowerCase.IndexOf(parentPathLowerCase) == 0); }
public bool IsChildOf(IDirectoryPath parentDirectory) { Argument.IsNotNull(nameof(parentDirectory), parentDirectory); var parentDirectoryString = parentDirectory.ToString(); // Don't accept equals pathString! var parentDirectoryStringLength = parentDirectoryString.Length; if (CurrentPath.Length <= parentDirectoryStringLength) { return(false); } // Possible since at this point (m_PathString.Length > parentDirectoryStringLength) var c = CurrentPath[parentDirectoryStringLength]; // Need to check that char at pos pathStringLength is a separator, // else @"D:/Foo bar" is considered as a child of @"D:/Foo". // Note that m_PathString is normalized in ctor, hence its separator(s) are DIR_SEPARATOR_CHAR. if (c != MiscHelpers.DirectorySeparatorChar) { return(false); } var parentPathLowerCase = parentDirectory.ToString().ToLower(); var thisPathLowerCase = CurrentPath.ToLower(); return(thisPathLowerCase.IndexOf(parentPathLowerCase, StringComparison.Ordinal) == 0); }
public bool IsChildOf(IDirectoryPath parentDirectory) { Argument.IsNotNull(nameof(parentDirectory), parentDirectory); var parentDirectoryString = parentDirectory.ToString(); // Don't accept equals pathString! var parentDirectoryStringLength = parentDirectoryString.Length; if (CurrentPath.Length <= parentDirectoryStringLength) { return false; } // Possible since at this point (m_PathString.Length > parentDirectoryStringLength) var c = CurrentPath[parentDirectoryStringLength]; // Need to check that char at pos pathStringLength is a separator, // else @"D:/Foo bar" is considered as a child of @"D:/Foo". // Note that m_PathString is normalized in ctor, hence its separator(s) are DIR_SEPARATOR_CHAR. if (c != MiscHelpers.DirectorySeparatorChar) { return false; } var parentPathLowerCase = parentDirectory.ToString().ToLower(); var thisPathLowerCase = CurrentPath.ToLower(); return thisPathLowerCase.IndexOf(parentPathLowerCase, StringComparison.Ordinal) == 0; }
internal static string GetChildDirectoryWithName(IDirectoryPath directoryPath, string directoryName) { Debug.Assert(directoryPath != null); Debug.Assert(directoryName != null); // Enforced by contract Debug.Assert(directoryName.Length > 0); // Enforced by contract return(directoryPath.ToString() + MiscHelpers.DIR_SEPARATOR_CHAR + directoryName); }
internal static string GetChildFileWithName(IDirectoryPath directoryPath, string fileName) { Debug.Assert(directoryPath != null); Debug.Assert(fileName != null); // Enforced by contract Debug.Assert(fileName.Length > 0); // Enforced by contract return directoryPath.ToString() + MiscHelpers.DIR_SEPARATOR_CHAR + fileName; }
static void GetProfiles(IDirectoryPath path, List <string> profiles, string ext) { if (Directory.Exists(path.ToString())) { profiles.AddRange(GetProfilesInternal(path, ext)); } }
internal static string GetChildDirectoryPath(IDirectoryPath directoryPath, string directoryName) { Argument.IsNotNull(nameof(directoryPath), directoryPath); Argument.IsNotNullOrEmpty(nameof(directoryName), directoryName); return directoryPath.ToString() + MiscHelpers.DirectorySeparatorChar + directoryName; }
internal static string GetChildDirectoryPath(IDirectoryPath directoryPath, string directoryName) { Argument.IsNotNull(nameof(directoryPath), directoryPath); Argument.IsNotNullOrEmpty(nameof(directoryName), directoryName); return(directoryPath.ToString() + MiscHelpers.DirectorySeparatorChar + directoryName); }
public bool IsChildOf(IDirectoryPath parentDirectory) { Debug.Assert(parentDirectory != null); string parentPathLowerCase = parentDirectory.ToString().ToLower(); string thisPathLowerCase = m_PathString.ToLower(); // Don't accept equals pathString! if (thisPathLowerCase.Length <= parentPathLowerCase.Length) { return false; } return thisPathLowerCase.IndexOf(parentPathLowerCase) == 0; }
public static void MakeSurePathExistsWithRetry(this IDirectoryPath path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } Tools.FileUtil.Ops.CreateDirectoryWithRetry(path.ToString()); }
static IEnumerable <string> GetProfilesInternal(IDirectoryPath path, string ext) { var filenames = Directory.EnumerateFiles(path.ToString(), "*." + ext, SearchOption.AllDirectories); return(from filename in filenames where !filename.Contains(".vars.") select Uri.UnescapeDataString(Path.GetFileNameWithoutExtension(filename))); }
public void Test_ParentDirectoryPath() { IDirectoryPath path = @".\File.txt".ToRelativeFilePath().ParentDirectoryPath; Assert.IsTrue(path.ToString() == @"."); path = @"C:\File.txt".ToAbsoluteFilePath().ParentDirectoryPath; Assert.IsTrue(path.ToString() == @"C:"); path = @".\\File.txt".ToRelativeFilePath().ParentDirectoryPath; Assert.IsTrue(path.ToString() == @"."); path = @"C:\\\\File.txt".ToAbsoluteFilePath().ParentDirectoryPath; Assert.IsTrue(path.ToString() == @"C:"); path = @"C:\dir1\\//dir2\File.txt".ToAbsoluteFilePath().ParentDirectoryPath; Assert.IsTrue(path.ToString() == @"C:\dir1\dir2"); }
public void Test_NormalizePath() { IDirectoryPath path = @".\".ToRelativeDirectoryPath(); Assert.IsTrue(path.ToString() == "."); path = @".\\\".ToRelativeDirectoryPath(); Assert.IsTrue(path.ToString() == "."); path = @".\\\..\\".ToRelativeDirectoryPath(); Assert.IsTrue(path.ToString() == ".."); path = @".\/dir1\//\dir2\/dir3///".ToRelativeDirectoryPath(); Assert.IsTrue(path.ToString() == @".\dir1\dir2\dir3"); path = "C:/dir1/dir2".ToAbsoluteDirectoryPath(); Assert.IsTrue(path.ToString() == @"C:\dir1\dir2"); }
public bool IsChildOf(IDirectoryPath parentDirectory) { Debug.Assert(parentDirectory != null); var parentDirectoryString = parentDirectory.ToString(); // Don't accept equals pathString! var parentDirectoryStringLength = parentDirectoryString.Length; if (m_PathString.Length <= parentDirectoryStringLength) { return false; } // Possible since at this point (m_PathString.Length > parentDirectoryStringLength) var c = m_PathString[parentDirectoryStringLength]; // Need to check that char at pos pathStringLength is a separator, // else @"D:/Foo bar" is considered as a child of @"D:/Foo". // Note that m_PathString is normalized in ctor, hence its separator(s) are DIR_SEPARATOR_CHAR. if (c != MiscHelpers.DIR_SEPARATOR_CHAR) { return false; } string parentPathLowerCase = parentDirectory.ToString().ToLower(); string thisPathLowerCase = m_PathString.ToLower(); return thisPathLowerCase.IndexOf(parentPathLowerCase) == 0; }
public bool IsChildOf(IDirectoryPath parentDirectory) { Debug.Assert(parentDirectory != null); string parentPathLowerCase = parentDirectory.ToString().ToLower(); string thisPathLowerCase = m_PathString.ToLower(); // Don't accept equals pathString! if (thisPathLowerCase.Length <= parentPathLowerCase.Length) { return(false); } return(thisPathLowerCase.IndexOf(parentPathLowerCase) == 0); }
public static IEnumerable <IAbsoluteFilePath> GetFiles(this IDirectoryPath path, IEnumerable <string> searchPatterns, SearchOption searchOption = SearchOption.TopDirectoryOnly) => GetFiles(path.ToString(), searchPatterns, searchOption).Select(x => x.ToAbsoluteFilePath());