/// <summary> /// Gets a value indicating if the FileSystemInfo object is currently available /// </summary> /// <param name="fsInfo"></param> /// <param name="recordedSerial">if a serial is specified the return value is more reliable.</param> /// <returns></returns> public static bool IsAvailable(FileSystemInfo fsInfo, string recordedSerial) { // Get Drive Information DriveInfo driveInfo = GetDriveInfo(fsInfo); // Refresh the object information (important) fsInfo.Refresh(); // Check if the file exists bool fileExists = fsInfo.Exists; // Do we have a logical volume? if (driveInfo != null && fileExists) { string currentSerial = driveInfo.GetVolumeSerial(); // if we have both the recorded and the current serial we can do this very exact // by checking if the serials match if (!String.IsNullOrEmpty(recordedSerial) && !String.IsNullOrEmpty(currentSerial)) // return the exact check result return (currentSerial == recordedSerial); } // return the simple check result return fileExists; }
private void RemoveReadOnlyFlagRecursive(FileSystemInfo info) { info.Refresh(); if (info is FileInfo) { new FileInfoWrapper(info as FileInfo).ReadOnly = false; } else if (info is DirectoryInfo) { new DirectoryInfoWrapper(info as DirectoryInfo).ReadOnly = false; foreach (var child in (info as DirectoryInfo).GetFileSystemInfos()) { this.RemoveReadOnlyFlagRecursive(child); } } }
/// <summary> /// Deletes the file or directory if it exists. /// </summary> /// <param name="info">FileInfo or DirectoryInfo instance</param> public void Delete(FileSystemInfo info) { if (info.Exists) info.Delete(); info.Refresh(); }
public void RefreshDirectory(FileSystemInfo e) { e.Refresh(); }
private void setAttributes(FileSystemInfo fi, ZipEntry entry) { DateTime? entryTimeUtc = getEntryTimeUtc(entry); if (entryTimeUtc != null) fi.LastWriteTimeUtc = entryTimeUtc.Value; if (isDos(entry) && (entry.ExternalFileAttributes != -1)) { const FileAttributes mask = (FileAttributes.Archive | FileAttributes.Normal | FileAttributes.ReadOnly | FileAttributes.Hidden | FileAttributes.System); var entryAttributes = (FileAttributes) entry.ExternalFileAttributes; fi.Refresh(); fi.Attributes = (fi.Attributes & ~mask) | (entryAttributes & mask); } }