示例#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;
 }
示例#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");
     }
      */
 }
示例#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;
 }
示例#4
0
 public virtual bool SetExecutable(FilePath path, bool exec)
 {
     return false;
 }
示例#5
0
 public virtual bool RenameTo(FilePath path, string name)
 {
     try {
         File.Move (path, name);
         return true;
     } catch {
         return false;
     }
 }
示例#6
0
 public FileWriter(FilePath path)
     : base(path.GetPath ())
 {
 }
示例#7
0
 public virtual bool IsDirectory(FilePath path)
 {
     return Directory.Exists (path);
 }
示例#8
0
 public virtual bool CanExecute(FilePath path)
 {
     return false;
 }
示例#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);
        }
示例#10
0
 public bool RenameTo(FilePath file)
 {
     return RenameTo (file.path);
 }
示例#11
0
 public FilePath(FilePath other, string child)
     : this((string) other, child)
 {
 }
示例#12
0
 public FileOutputStream(FilePath file)
     : this(file.GetPath (), false)
 {
 }
示例#13
0
 public FileOutputStream(FilePath file, bool append)
     : this(file.GetPath (), append)
 {
 }
示例#14
0
 public FileReader(FilePath f)
     : base(f.GetPath ())
 {
 }
示例#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;
        }
示例#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;
     }
 }
示例#17
0
 public RandomAccessFile(FilePath file, string mode)
     : this(file.GetPath (), mode)
 {
 }
示例#18
0
 public virtual bool CanWrite(FilePath path)
 {
     return ((File.GetAttributes (path) & FileAttributes.ReadOnly) == 0);
 }
示例#19
0
 public static void DeleteFile(string filename)
 {
     FilePath file = new FilePath(filename);
     file.Delete();
 }
示例#20
0
 public virtual bool Exists(FilePath path)
 {
     return (File.Exists (path) || Directory.Exists (path));
 }
示例#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);
     }
 }
示例#22
0
 public virtual bool IsFile(FilePath path)
 {
     return File.Exists (path);
 }
示例#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);
     }
 }
示例#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;
 }
示例#25
0
 public FileInputStream(FilePath file)
     : this(file.GetPath ())
 {
 }