Exemple #1
0
        private static string[] GetChildren(string path, string searchPattern, bool isDirectory)
        {
            // path and searchPattern validation in Path.GetFullPath() and Path.NormalizePath()

            path = Path.GetFullPath(path);
            Path.NormalizePath(searchPattern, true);

            ArrayList fileNames = new ArrayList();

            string root = Path.GetPathRoot(path);

            if (String.Equals(root, path))
            {
                /// This is special case. Return all the volumes.
                /// Note this will not work, once we start having \\server\share like paths.

                if (isDirectory)
                {
                    VolumeInfo[] volumes = VolumeInfo.GetVolumes();
                    int          count   = volumes.Length;
                    for (int i = 0; i < count; i++)
                    {
                        fileNames.Add(volumes[i].RootDirectory);
                    }
                }
            }
            else
            {
                Object         record = FileSystemManager.AddToOpenListForRead(path);
                NativeFindFile ff     = null;
                try
                {
                    ff = new NativeFindFile(path, searchPattern);

                    uint targetAttribute = (isDirectory ? (uint)FileAttributes.Directory : 0);

                    NativeFileInfo fileinfo = ff.GetNext();

                    while (fileinfo != null)
                    {
                        if ((fileinfo.Attributes & (uint)FileAttributes.Directory) == targetAttribute)
                        {
                            fileNames.Add(fileinfo.FileName);
                        }

                        fileinfo = ff.GetNext();
                    }
                }
                finally
                {
                    if (ff != null)
                    {
                        ff.Close();
                    }
                    FileSystemManager.RemoveFromOpenList(record);
                }
            }

            return((String[])fileNames.ToArray(typeof(String)));
        }
Exemple #2
0
 public static string GetDirectoryName(string path)
 {
     if (path != null)
     {
         Path.CheckInvalidPathChars(path, false);
         string str1 = Path.NormalizePath(path, false);
         if (path.Length > 0)
         {
             try
             {
                 string str2   = Path.RemoveLongPathPrefix(path);
                 int    length = 0;
                 while (length < str2.Length && (int)str2[length] != 63 && (int)str2[length] != 42)
                 {
                     ++length;
                 }
                 if (length > 0)
                 {
                     Path.GetFullPath(str2.Substring(0, length));
                 }
             }
             catch (SecurityException ex)
             {
                 if (path.IndexOf("~", StringComparison.Ordinal) != -1)
                 {
                     str1 = Path.NormalizePath(path, false, false);
                 }
             }
             catch (PathTooLongException ex)
             {
             }
             catch (NotSupportedException ex)
             {
             }
             catch (IOException ex)
             {
             }
             catch (ArgumentException ex)
             {
             }
         }
         path = str1;
         int rootLength = Path.GetRootLength(path);
         if (path.Length > rootLength)
         {
             int length = path.Length;
             if (length == rootLength)
             {
                 return((string)null);
             }
             do
             {
                 ;
             }while (length > rootLength && (int)path[--length] != (int)Path.DirectorySeparatorChar && (int)path[length] != (int)Path.AltDirectorySeparatorChar);
             return(path.Substring(0, length));
         }
     }
     return((string)null);
 }
Exemple #3
0
 internal static string GetFullPathInternal(string path)
 {
     if (path == null)
     {
         throw new ArgumentNullException("path");
     }
     return(Path.NormalizePath(path, true));
 }
Exemple #4
0
 public static string GetPathRoot(string path)
 {
     if (path == null)
     {
         return((string)null);
     }
     path = Path.NormalizePath(path, false);
     return(path.Substring(0, Path.GetRootLength(path)));
 }
Exemple #5
0
 public static string GetDirectoryName(string path)
 {
     if (path != null)
     {
         Path.CheckInvalidPathChars(path);
         path = Path.NormalizePath(path, false);
         int rootLength = Path.GetRootLength(path);
         if (path.Length > rootLength)
         {
             int length = path.Length;
             if (length == rootLength)
             {
                 return((string)null);
             }
             do
             {
                 ;
             }while (length > rootLength && (int)path[--length] != (int)Path.DirectorySeparatorChar && (int)path[length] != (int)Path.AltDirectorySeparatorChar);
             return(path.Substring(0, length));
         }
     }
     return((string)null);
 }
 internal unsafe static String NormalizePath(String path, bool fullCheck)
 {
     Contract.Requires(path != null);
     return(Path.NormalizePath(path, fullCheck, Path.MaxLongPath));
 }
Exemple #7
0
 internal static string NormalizePath(string path, bool fullCheck)
 {
     return(Path.NormalizePath(path, fullCheck, 32000));
 }
 internal static string NormalizePath(string path, bool fullCheck)
 {
     return(Path.NormalizePath(path, fullCheck, Path.MaxLongPath));
 }
Exemple #9
0
        private static string[] GetChildren(string path, string searchPattern, bool isDirectory)
        {
            // path and searchPattern validation in Path.GetFullPath() and Path.NormalizePath()

            path = Path.GetFullPath(path);

            if (!Directory.Exists(path))
            {
                throw new IOException("", (int)IOException.IOExceptionErrorCode.DirectoryNotFound);
            }

            Path.NormalizePath(searchPattern, true);

            var fileNames = new ArrayList();

            var root = Path.GetPathRoot(path);

            if (false && string.Equals(root, path))   //TODO check to see it always go here
            /// This is special case. Return all the volumes.
            /// Note this will not work, once we start having \\server\share like paths.

            {
                if (isDirectory)
                {
                    var volumes = DriveInfo.GetDrives();
                    var count   = volumes.Length;
                    for (var i = 0; i < count; i++)
                    {
                        fileNames.Add(volumes[i].RootDirectory.Name);
                    }
                }
            }
            else
            {
                var record = FileSystemManager.AddToOpenListForRead(path);
                IFileSystemEntryFinder ff = null;
                try {
                    ff = DriveInfo.GetForPath(path).Find(path, searchPattern);

                    var targetAttribute = (isDirectory ? FileAttributes.Directory : 0);

                    var fileinfo = ff.GetNext();

                    while (fileinfo != null)
                    {
                        if ((fileinfo.Attributes & FileAttributes.Directory) == targetAttribute)
                        {
                            fileNames.Add(fileinfo.FileName);
                        }

                        fileinfo = ff.GetNext();
                    }
                }
                finally {
                    if (ff != null)
                    {
                        ff.Close();
                    }
                    FileSystemManager.RemoveFromOpenList(record);
                }
            }

            return((string[])fileNames.ToArray(typeof(string)));
        }
Exemple #10
0
 internal static string NormalizePath(string path, bool fullCheck, int maxPathLength)
 {
     return(Path.NormalizePath(path, fullCheck, maxPathLength, true));
 }
Exemple #11
0
 internal static string NormalizePath(string path, bool fullCheck, bool expandShortPaths)
 {
     return(Path.NormalizePath(path, fullCheck, Path.MaxPath, expandShortPaths));
 }