Esempio n. 1
0
        static List <file_system_item> get_directories(string path)
        {
            List <file_system_item> t_item = new List <file_system_item>();

            try{
                List <string> t_dir = Directory.GetDirectories(path).OrderBy(f => f).ToList();
                foreach (string t in t_dir)
                {
                    file_system_item tf  = new file_system_item();
                    DirectoryInfo    dir = new DirectoryInfo(t);
                    if ((dir.Attributes & FileAttributes.Hidden) == (FileAttributes.Hidden))
                    {
                        tf.hidden = true;
                    }
                    DateTime dt = Directory.GetLastWriteTime(t);
                    tf.type     = "folder";
                    tf.path     = t;
                    tf.modified = core.relative_time(dt);
                    string[] tokens = t.Split(new char[] { '/', '\\' });
                    tf.name = tokens.Last();
                    t_item.Add(tf);
                }
            }catch (UnauthorizedAccessException) {
            }
            return(t_item);
        }
Esempio n. 2
0
        static List <file_system_item> get_files(dir_path path)
        {
            List <file_system_item> t_item = new List <file_system_item>();

            try{
                var           sorted  = Directory.GetFiles(".").OrderBy(f => f);
                List <string> t_files = Directory.GetFiles(path.path, "*", SearchOption.TopDirectoryOnly)
                                        .Where((string x) =>
                {
                    if (null == path.filters || !path.filters.Any())
                    {
                        return(true);
                    }
                    foreach (string z in  path.filters)
                    {
                        if (x.EndsWith(z, StringComparison.CurrentCulture))
                        {
                            return(true);
                        }
                    }
                    return(false);
                }).OrderBy(f => f).ToList();
                foreach (string t in t_files)
                {
                    file_system_item tf = new file_system_item();
                    var fInfo           = new FileInfo(t);
                    if (fInfo.Attributes.HasFlag(FileAttributes.Hidden))
                    {
                        tf.hidden = true;
                    }
                    DateTime dt = File.GetLastWriteTime(t);

                    tf.type      = "file";
                    tf.path      = t;
                    tf.size      = get_file_size(t);
                    tf.modified  = core.relative_time(dt);
                    tf.name      = Path.GetFileName(t);
                    tf.extension = Path.GetExtension(t);
                    t_item.Add(tf);
                }
            }catch (UnauthorizedAccessException) {
            }
            return(t_item);
        }