public virtual long LastModified(FilePath path) { if (IsFile(path)) { var info2 = new FileInfo(path); return info2.Exists ? info2.LastWriteTimeUtc.ToMillisecondsSinceEpoch() : 0; } else if (IsDirectory (path)) { var info = new DirectoryInfo(path); return info.Exists ? info.LastWriteTimeUtc.ToMillisecondsSinceEpoch() : 0; } return 0; }
/// <exception cref="System.IO.IOException"></exception> private void Init() { file = new FilePath(filename); if (!file.Exists()) { throw new FileNotFoundException("File not found " + filename); } /* if (!file.CanRead()) { throw new IOException("File not readable"); } */ }
public virtual bool Delete(FilePath path) { if (Directory.Exists (path)) { if (Directory.GetFileSystemEntries (path).Length != 0) return false; MakeDirWritable (path); Directory.Delete (path, true); return true; } else if (File.Exists(path)) { MakeFileWritable (path); File.Delete (path); return true; } return false; }
public virtual bool SetExecutable(FilePath path, bool exec) { return false; }
public virtual bool RenameTo(FilePath path, string name) { try { File.Move (path, name); return true; } catch { return false; } }
public FileWriter(FilePath path) : base(path.GetPath ()) { }
public virtual bool IsDirectory(FilePath path) { return Directory.Exists (path); }
public virtual bool CanExecute(FilePath path) { return false; }
public static FilePath CreateTempFile(string prefix, string suffix, FilePath directory) { string file; if (prefix == null) { throw new ArgumentNullException ("prefix"); } if (prefix.Length < 3) { throw new ArgumentException ("prefix must have at least 3 characters"); } string str = (directory == null) ? Path.GetTempPath () : directory.GetPath (); do { file = Path.Combine (str, prefix + Interlocked.Increment (ref tempCounter) + suffix); } while (File.Exists (file)); new FileOutputStream (file).Close (); return new FilePath (file); }
public bool RenameTo(FilePath file) { return RenameTo (file.path); }
public FilePath(FilePath other, string child) : this((string) other, child) { }
public FileOutputStream(FilePath file) : this(file.GetPath (), false) { }
public FileOutputStream(FilePath file, bool append) : this(file.GetPath (), append) { }
public FileReader(FilePath f) : base(f.GetPath ()) { }
public virtual bool SetLastModified(FilePath path, long milis) { try { DateTime utcDateTime = Extensions.MillisToDateTimeOffset(milis, 0L).UtcDateTime; if (IsFile(path)) { var info2 = new FileInfo(path); info2.LastWriteTimeUtc = utcDateTime; return true; } else if (IsDirectory(path)) { var info = new DirectoryInfo(path); info.LastWriteTimeUtc = utcDateTime; return true; } } catch { } return false; }
public virtual bool SetReadOnly(FilePath path) { try { var fileAttributes = File.GetAttributes (path) | FileAttributes.ReadOnly; File.SetAttributes (path, fileAttributes); return true; } catch { return false; } }
public RandomAccessFile(FilePath file, string mode) : this(file.GetPath (), mode) { }
public virtual bool CanWrite(FilePath path) { return ((File.GetAttributes (path) & FileAttributes.ReadOnly) == 0); }
public static void DeleteFile(string filename) { FilePath file = new FilePath(filename); file.Delete(); }
public virtual bool Exists(FilePath path) { return (File.Exists (path) || Directory.Exists (path)); }
public virtual void MakeDirWritable(FilePath path) { foreach (string file in Directory.GetFiles (path)) { MakeFileWritable (file); } foreach (string subdir in Directory.GetDirectories (path)) { MakeDirWritable (subdir); } }
public virtual bool IsFile(FilePath path) { return File.Exists (path); }
public virtual void MakeFileWritable(FilePath file) { FileAttributes fileAttributes = File.GetAttributes (file); if ((fileAttributes & FileAttributes.ReadOnly) != 0) { fileAttributes &= ~FileAttributes.ReadOnly; File.SetAttributes (file, fileAttributes); } }
public virtual long Length(FilePath path) { // If you call .Length on a file that doesn't exist, an exception is thrown var info2 = new FileInfo (path); return info2.Exists ? info2.Length : 0; }
public FileInputStream(FilePath file) : this(file.GetPath ()) { }