Exemple #1
0
 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;
 }
Exemple #2
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");
     }
      */
 }
Exemple #3
0
 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;
 }
Exemple #4
0
 public virtual bool SetExecutable(FilePath path, bool exec)
 {
     return false;
 }
Exemple #5
0
 public virtual bool RenameTo(FilePath path, string name)
 {
     try {
         File.Move (path, name);
         return true;
     } catch {
         return false;
     }
 }
Exemple #6
0
 public FileWriter(FilePath path)
     : base(path.GetPath ())
 {
 }
Exemple #7
0
 public virtual bool IsDirectory(FilePath path)
 {
     return Directory.Exists (path);
 }
Exemple #8
0
 public virtual bool CanExecute(FilePath path)
 {
     return false;
 }
Exemple #9
0
        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);
        }
Exemple #10
0
 public bool RenameTo(FilePath file)
 {
     return RenameTo (file.path);
 }
Exemple #11
0
 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)
 {
 }
Exemple #14
0
 public FileReader(FilePath f)
     : base(f.GetPath ())
 {
 }
Exemple #15
0
        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;
        }
Exemple #16
0
 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)
 {
 }
Exemple #18
0
 public virtual bool CanWrite(FilePath path)
 {
     return ((File.GetAttributes (path) & FileAttributes.ReadOnly) == 0);
 }
Exemple #19
0
 public static void DeleteFile(string filename)
 {
     FilePath file = new FilePath(filename);
     file.Delete();
 }
Exemple #20
0
 public virtual bool Exists(FilePath path)
 {
     return (File.Exists (path) || Directory.Exists (path));
 }
Exemple #21
0
 public virtual void MakeDirWritable(FilePath path)
 {
     foreach (string file in Directory.GetFiles (path)) {
         MakeFileWritable (file);
     }
     foreach (string subdir in Directory.GetDirectories (path)) {
         MakeDirWritable (subdir);
     }
 }
Exemple #22
0
 public virtual bool IsFile(FilePath path)
 {
     return File.Exists (path);
 }
Exemple #23
0
 public virtual void MakeFileWritable(FilePath file)
 {
     FileAttributes fileAttributes = File.GetAttributes (file);
     if ((fileAttributes & FileAttributes.ReadOnly) != 0) {
         fileAttributes &= ~FileAttributes.ReadOnly;
         File.SetAttributes (file, fileAttributes);
     }
 }
Exemple #24
0
 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;
 }
Exemple #25
0
 public FileInputStream(FilePath file)
     : this(file.GetPath ())
 {
 }