Exemplo n.º 1
0
 // Set the attributes on a file.
 public static void SetAttributes
     (String path, FileAttributes fileAttributes)
 {
     Directory.ValidatePath(path);
     Directory.HandleErrorsFile
         (FileMethods.SetAttributes(path, (int)fileAttributes));
 }
Exemplo n.º 2
0
 // Set the UTC last modification time on a file.
 public static void SetLastWriteTimeUtc(String path, DateTime lastWriteTime)
 {
     Directory.ValidatePath(path);
     Directory.HandleErrorsFile
         (FileMethods.SetLastWriteTime
             (path, lastWriteTime.Ticks));
 }
Exemplo n.º 3
0
 // Set the creation time on a file.
 public static void SetCreationTime(String path, DateTime creationTime)
 {
     Directory.ValidatePath(path);
     Directory.HandleErrorsFile
         (FileMethods.SetCreationTime
             (path, creationTime.ToUniversalTime().Ticks));
 }
Exemplo n.º 4
0
 // Set the last access time on a file.
 public static void SetLastAccessTime(String path, DateTime lastAccessTime)
 {
     Directory.ValidatePath(path);
     Directory.HandleErrorsFile
         (FileMethods.SetLastAccessTime
             (path, lastAccessTime.ToUniversalTime().Ticks));
 }
Exemplo n.º 5
0
        // Get the length of a file.
        internal static long GetLength(String path)
        {
            long length;

            Directory.ValidatePath(path);
            Directory.HandleErrorsFile
                (FileMethods.GetLength(path, out length));
            return(length);
        }
Exemplo n.º 6
0
        // Get a file's UTC last modification time.
        public static DateTime GetLastWriteTimeUtc(String path)
        {
            long ticks;

            Directory.ValidatePath(path);
            Directory.HandleErrorsFile
                (DirMethods.GetLastModification(path, out ticks));
            return(new DateTime(ticks));
        }
Exemplo n.º 7
0
        // Get the attributes for a file.
        public static FileAttributes GetAttributes(String path)
        {
            int attrs;

            Directory.ValidatePath(path);
            Directory.HandleErrorsFile
                (FileMethods.GetAttributes(path, out attrs));
            return((FileAttributes)attrs);
        }
Exemplo n.º 8
0
        // Get a file's last access time.
        public static DateTime GetLastAccessTime(String path)
        {
            long ticks;

            Directory.ValidatePath(path);
            Directory.HandleErrorsFile
                (DirMethods.GetLastAccess(path, out ticks));
            return((new DateTime(ticks)).ToLocalTime());
        }
Exemplo n.º 9
0
        // Delete a file.
        public static void Delete(String path)
        {
            Directory.ValidatePath(path);
            Errno errno = DirMethods.Delete(path);

            if (errno != Errno.ENOENT)
            {
                Directory.HandleErrorsFile(errno);
            }
        }
Exemplo n.º 10
0
        // Create a symbolic link at "newpath" that points to "oldpath".
        // Throws "NotSupportedException" if the filesystem does not
        // support the creation of symbolic links or ".lnk" files.
        public static void CreateLink(String oldpath, String newpath)
        {
            // Validate and normalize the parameters.
            Directory.ValidatePath(oldpath);
            Directory.ValidatePath(newpath);
            oldpath = Path.NormalizeSeparators(oldpath);
            newpath = Path.NormalizeSeparators(newpath);

            // Try to create the symlink using the engine.
            Errno error = FileMethods.CreateLink(oldpath, newpath);

            if (error == Errno.Success)
            {
                return;
            }
            else if (error != Errno.EPERM)
            {
                Directory.HandleErrorsFile(error);
            }

            // Bail out if we are not on Windows.
            if (!IsWindows())
            {
                throw new NotSupportedException(_("IO_NotSupp_Symlinks"));
            }

            // Make sure that we have ".lnk" on the end of the pathname.
            if (!EndsInLnk(newpath))
            {
                if (FileMethods.GetFileType(newpath) != FileType.unknown)
                {
                    // There already exists something at this location.
                    Directory.HandleErrorsFile(Errno.EEXIST);
                }
                newpath += ".lnk";
            }
            if (FileMethods.GetFileType(newpath) != FileType.unknown)
            {
                // There already exists something at this location.
                Directory.HandleErrorsFile(Errno.EEXIST);
            }

            // Create the shortcut information to place in the file.
            ShortcutInformation info = new ShortcutInformation();

            info.Description  = oldpath;
            info.RelativePath = oldpath;
            info.ShowWindow   = ShowWindow.Normal;

            // Write the shortcut information to the file.
            WriteShortcut(newpath, info, false);
        }
Exemplo n.º 11
0
        // Determine whether a file exists.
        public static bool Exists(String path)
        {
            try
            {
                Directory.ValidatePath(path);
            }
            catch (Exception)
            {
                return(false);
            }
            FileType type = FileMethods.GetFileType(path);

            return(type != FileType.directory &&
                   type != FileType.unknown);
        }
Exemplo n.º 12
0
        // Read the contents of a symbolic link.  Returns null if not a
        // symbolic link, or throws an exception if the pathname is invalid.
        public static String ReadLink(String pathname)
        {
            // Validate the parameter and normalize it.
            Directory.ValidatePath(pathname);
            pathname = Path.NormalizeSeparators(pathname);

            // Read the contents of the symlink using the engine.
            String contents;
            Errno  error = FileMethods.ReadLink(pathname, out contents);

            if (error != Errno.Success)
            {
                Directory.HandleErrorsFile(error);
            }
            if (contents != null)
            {
                return(contents);
            }

            // Bail out if we aren't on Windows.
            if (!IsWindows())
            {
                return(null);
            }

            // Make sure that we have ".lnk" on the end of the name.
            if (!EndsInLnk(pathname))
            {
                if (FileMethods.GetFileType(pathname) != FileType.unknown)
                {
                    // Something exists here and it does not have a ".lnk"
                    // extension, so it cannot possibly be a symlink.
                    return(null);
                }
                pathname += ".lnk";
            }
            FileType type = FileMethods.GetFileType(pathname);

            if (type == FileType.unknown)
            {
                // The pathname does not exist.
                Directory.HandleErrorsFile(Errno.ENOENT);
            }
            else if (type != FileType.regularFile)
            {
                // The pathname exists but it is not a regular file,
                // so it cannot possibly be a symbolic link.
                return(null);
            }

            // Read the contents of the Windows shortcut file.
            ShortcutInformation info = ReadShortcut(pathname);

            if (info == null)
            {
                return(null);
            }
            else
            {
                return(info.RelativePath);
            }
        }