Ejemplo n.º 1
0
        // Get the UTC last modification time of a directory.
        public static DateTime GetLastWriteTimeUtc(String path)
        {
            long time;

            ValidatePath(path);
            HandleErrorsDir(DirMethods.GetLastModification(path, out time));
            return(new DateTime(time));
        }
Ejemplo n.º 2
0
        // Get the last access time of a directory.
        public static DateTime GetLastAccessTime(String path)
        {
            long time;

            ValidatePath(path);
            HandleErrorsDir(DirMethods.GetLastAccess(path, out time));
            return((new DateTime(time)).ToLocalTime());
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
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());
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        // Initialize the special operating system characters.
        static Path()
        {
            PathInfo info = DirMethods.GetPathInfo();

            AltDirectorySeparatorChar = info.altDirSeparator;
            DirectorySeparatorChar    = info.dirSeparator;
            PathSeparator             = info.pathSeparator;
            VolumeSeparatorChar       = info.volumeSeparator;
            InvalidPathChars          = info.invalidPathChars;
        }
Ejemplo n.º 7
0
        // Get the current working directory.
        public static String GetCurrentDirectory()
        {
            String dir = DirMethods.GetCurrentDirectory();

            if (dir == null)
            {
                throw new UnauthorizedAccessException
                          (_("IO_AccessDenied"));
            }
            return(dir);
        }
Ejemplo n.º 8
0
        public static void Delete(String path, bool recursive)
        {
            // Remove trailing directory separators.
            if (path != null)
            {
                int len = path.Length - 1;
                if (len > 0)
                {
                    if (path[len] == Path.DirectorySeparatorChar ||
                        path[len] == Path.AltDirectorySeparatorChar)
                    {
                        path = path.Substring(0, len);
                    }
                }
            }

            // Validate the pathname.
            ValidatePath(path);

            // Recursively delete the directory's contents if necessary.
            if (recursive)
            {
                InternalFileInfo[] entries;
                int    posn;
                String filename;
                if (DirMethods.GetFilesInDirectory(path, out entries)
                    == Errno.Success && entries != null)
                {
                    for (posn = 0; posn < entries.Length; ++posn)
                    {
                        filename = entries[posn].fileName;
                        if (filename == "." || filename == "..")
                        {
                            continue;
                        }
                        filename = path + Path.DirectorySeparatorChar +
                                   filename;
                        if (entries[posn].fileType == FileType.directory)
                        {
                            Delete(filename, true);
                        }
                        else
                        {
                            File.Delete(filename);
                        }
                    }
                }
            }

            // Delete the directory itself.
            HandleErrorsDir(DirMethods.Delete(path));
        }
Ejemplo n.º 9
0
        public static string GetResultDir(string currentDirectoryPath, string extra)
        {
            res = "";
            DirMethods delDir = new DirMethods(Controls.Dir);

            delDir += Controls.DirFiles;
            delDir += Controls.DirFolders;
            delDir += Controls.DirFilesExtension;
            delDir += Controls.DirHelp;

            delDir(currentDirectoryPath, extra);

            return(res);
        }//GetResult
Ejemplo n.º 10
0
        // Create a subkey underneath this particular registry key.
        public IRegistryKeyProvider CreateSubKey(String subkey)
        {
            String dir = directory + Path.DirectorySeparatorChar + subkey;

            if (Directory.Exists(dir))
            {
                return(new FileKeyProvider(this, subkey));
            }
            Errno error = DirMethods.CreateDirectory(dir);

            if (error == Errno.Success || error == Errno.EEXIST)
            {
                return(new FileKeyProvider(this, subkey));
            }
            throw new ArgumentException(_("IO_RegistryKeyNotExist"));
        }
Ejemplo n.º 11
0
        // Create a directory, including parent directories.
        public static DirectoryInfo CreateDirectory(String path)
        {
            // Brubbel 2004-07-01: remove slashes and backslashes at end of path, if not you'll get an exception
            while (path.EndsWith("/"))
            {
                path = path.Remove(path.Length - 1, 1);
            }
            while (path.EndsWith("\\"))
            {
                path = path.Remove(path.Length - 1, 1);
            }
            // Brubbel End.
            ValidatePath(path);
            Errno error = DirMethods.CreateDirectory(path);

            if (error != Errno.Success)
            {
                // The path may already exist.
                if (Exists(path))
                {
                    return(new DirectoryInfo(path));
                }

                // Attempt to create the parent directory.
                String parent = Path.GetDirectoryName(path);
                if (parent == null)
                {
                    HandleErrorsDir(error);
                }
                CreateDirectory(parent);

                // Now try creating the child directory again.
                error = DirMethods.CreateDirectory(path);
                if (error != Errno.Success)
                {
                    HandleErrorsDir(error);
                }
            }
            return(new DirectoryInfo(path));
        }
Ejemplo n.º 12
0
 // Get a list of logical drives on the system.
 public static String[] GetLogicalDrives()
 {
     return(DirMethods.GetLogicalDrives());
 }
Ejemplo n.º 13
0
        // Get a path to a specific system folder.
        public static String GetFolderPath(SpecialFolder folder)
        {
            // We can use the operating system under Win32.
            if (InfoMethods.GetPlatformID() != PlatformID.Unix)
            {
                // Allocate a buffer to hold the result path.
                IntPtr buffer = Marshal.AllocHGlobal(260 /*MAX_PATH*/ + 1);

                // Call "SHGetFolderPath" to retrieve the path.
                try
                {
                    SHGetFolderPathA(IntPtr.Zero, (int)folder,
                                     IntPtr.Zero, 0, buffer);
                    String value = Marshal.PtrToStringAnsi(buffer);
                    if (value != null && value.Length != 0)
                    {
                        Marshal.FreeHGlobal(buffer);
                        return(value);
                    }
                }
                catch (Exception)
                {
                    // We weren't able to find the function in the DLL.
                }
                Marshal.FreeHGlobal(buffer);
            }

            // Special handling for some of the cases.
            String dir = null;

            switch (folder)
            {
            case SpecialFolder.System:
            {
                dir = DirMethods.GetSystemDirectory();
            }
            break;

            case SpecialFolder.ApplicationData:
            {
                dir = InfoMethods.GetUserStorageDir() +
                      Path.DirectorySeparatorChar +
                      "ApplicationData";
            }
            break;

            case SpecialFolder.LocalApplicationData:
            {
                dir = InfoMethods.GetUserStorageDir() +
                      Path.DirectorySeparatorChar +
                      "LocalApplicationData";
            }
            break;

            case SpecialFolder.CommonApplicationData:
            {
                dir = InfoMethods.GetUserStorageDir() +
                      Path.DirectorySeparatorChar +
                      "CommonApplicationData";
            }
            break;
            }
            if (dir != null && dir.Length > 0)
            {
                return(dir);
            }

            // The empty string indicates that the value is not present.
            return(String.Empty);
        }
Ejemplo n.º 14
0
 // Set the current directory.
 public static void SetCurrentDirectory(String path)
 {
     ValidatePath(path);
     HandleErrorsDir(DirMethods.ChangeDirectory(path));
 }
Ejemplo n.º 15
0
 // Move a file or directory to a new location.
 public static void Move(String sourceDirName, String destDirName)
 {
     ValidatePath(sourceDirName);
     ValidatePath(destDirName);
     HandleErrorsFile(DirMethods.Rename(sourceDirName, destDirName));
 }
Ejemplo n.º 16
0
        // Scan a directory to collect up all entries that match
        // the specified search criteria, returning FileSystemInfo's.
        internal static Object ScanDirectoryForInfos
            (String path, String searchPattern,
            ScanType scanType, Type arrayType)
        {
            Regex     regex;
            ArrayList list;

            InternalFileInfo[] entries;
            Errno    error;
            int      posn;
            String   filename;
            FileType type;

            // Get all files in the directory.
            error = DirMethods.GetFilesInDirectory(path, out entries);
            if (error != Errno.Success)
            {
                HandleErrorsDir(error);
            }
            if (entries == null)
            {
                return(new String [0]);
            }

            // Convert the search pattern into a regular expression.
            if (searchPattern == null)
            {
                regex = null;
            }
            else
            {
                regex = new Regex(searchPattern, RegexSyntax.Wildcard);
            }

            // Scan the file list and collect up matching entries.
            list = new ArrayList(entries.Length);
            for (posn = 0; posn < entries.Length; ++posn)
            {
                filename = entries[posn].fileName;
                if (filename == "." || filename == "..")
                {
                    continue;
                }
                type = entries[posn].fileType;
                switch (scanType)
                {
                case ScanType.Directories:
                {
                    if (type != FileType.directory)
                    {
                        continue;
                    }
                }
                break;

                case ScanType.Files:
                {
                    if (type == FileType.directory)
                    {
                        continue;
                    }
                }
                break;

                default: break;
                }
                if (regex != null && !regex.Match(filename))
                {
                    continue;
                }
                if (type == FileType.directory)
                {
                    list.Add(new DirectoryInfo
                                 (Path.Combine(path, filename)));
                }
                else
                {
                    list.Add(new FileInfo(Path.Combine(path, filename)));
                }
            }

            // Dispose of the regular expression.
            if (regex != null)
            {
                regex.Dispose();
            }

            // Return the list of strings to the caller.
            return(list.ToArray(arrayType));
        }