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))); }
public static void SetCurrentDirectory(string path) { // path validation in Path.GetFullPath() path = Path.GetFullPath(path); // We lock the directory for read-access first, to ensure path won't get deleted Object record = FileSystemManager.AddToOpenListForRead(path); try { if (!Directory.Exists(path)) { throw new IOException("", (int)IOException.IOExceptionErrorCode.DirectoryNotFound); } // This will put the actual lock on path. (also read-access) FileSystemManager.SetCurrentDirectory(path); } finally { // We take our lock off. FileSystemManager.RemoveFromOpenList(record); } }
public FileEnum(string path, FileEnumFlags flags) { this.m_flags = flags; this.m_path = path; this.m_openForReadHandle = FileSystemManager.AddToOpenListForRead(this.m_path); this.m_findFile = DriveInfo.GetForPath(this.m_path).Find(this.m_path, "*"); }
public FileEnum(string path, FileEnumFlags flags) { m_flags = flags; m_path = path; m_openForReadHandle = FileSystemManager.AddToOpenListForRead(m_path); m_findFile = new NativeFindFile(m_path, "*"); }
public void Reset() { if (this.m_disposed) { throw new ObjectDisposedException(); } if (this.m_findFile != null) { this.m_findFile.Close(); } if (this.m_openForReadHandle == null) { this.m_openForReadHandle = FileSystemManager.AddToOpenListForRead(this.m_path); } this.m_findFile = DriveInfo.GetForPath(this.m_path).Find(this.m_path, "*"); }
public void Refresh() { var record = FileSystemManager.AddToOpenListForRead(this.m_fullPath); try { this._nativeFileInfo = DriveInfo.GetForPath(this.m_fullPath).GetFileSystemEntry(this.m_fullPath); if (this._nativeFileInfo == null) { var errorCode = (this is FileInfo) ? IOException.IOExceptionErrorCode.FileNotFound : IOException.IOExceptionErrorCode.DirectoryNotFound; throw new IOException("", (int)errorCode); } } finally { FileSystemManager.RemoveFromOpenList(record); } }
public void Refresh() { Object record = FileSystemManager.AddToOpenListForRead(m_fullPath); try { _nativeFileInfo = NativeFindFile.GetFileInfo(m_fullPath); if (_nativeFileInfo == null) { IOException.IOExceptionErrorCode errorCode = (this is FileInfo) ? IOException.IOExceptionErrorCode.FileNotFound : IOException.IOExceptionErrorCode.DirectoryNotFound; throw new IOException("", (int)errorCode); } } finally { FileSystemManager.RemoveFromOpenList(record); } }
public void Reset() { if (m_disposed) { throw new ObjectDisposedException(); } if (m_findFile != null) { m_findFile.Close(); } if (m_openForReadHandle == null) { m_openForReadHandle = FileSystemManager.AddToOpenListForRead(m_path); } m_findFile = new NativeFindFile(m_path, "*"); }
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))); }