Ejemplo n.º 1
0
        public string OldestFile(string dir, string ext)
        {
            try
            {
                if (System.IO.Directory.Exists(dir))
                {
                    if (ext.Length < 3)
                    {
                        return("Invalid extension (3 characters are required)");
                    }
                    else
                    {
                        FileLister _files;
                        _files = new FileLister(ext, dir, false);

                        if (_files.count < 1)
                        {
                            return("No Files Found");
                        }
                        else
                        {
                            return(_files.CurrentFiles.OrderByDescending(x => x.FileCreationDate).Last().FileName);
                        }
                    }
                }
                else
                {
                    return("Directory does not exist");
                }
            }
            catch (System.Exception) { throw; }
        }
Ejemplo n.º 2
0
        public string ListFilesXML(string dir, string ext, bool doSubFolders = false)
        {
            string     result = string.Empty;
            FileLister _files;

            try
            {
                if (System.IO.Directory.Exists(dir))
                {
                    if (ext.Length < 3)
                    {
                        result = "Invalid extension (3 characters are required)";
                    }
                    else
                    {
                        _files = new FileLister(ext, dir, doSubFolders);

                        if (_files.count < 1)
                        {
                            result = "No Files Found";
                        }
                        else
                        {
                            using (var sw = new StringWriter())
                            {
                                using (var xw = XmlWriter.Create(sw))
                                {
                                    xw.WriteStartDocument();
                                    xw.WriteStartElement("files");

                                    foreach (FileDetail x in _files.CurrentFiles)
                                    {
                                        xw.WriteStartElement("file");
                                        xw.WriteElementString("name", x.FileName);
                                        xw.WriteElementString("path", x.FilePath);
                                        xw.WriteEndElement();
                                    }

                                    xw.WriteEndElement();
                                    xw.WriteEndDocument();
                                }

                                return(sw.ToString());
                            }
                        }

                        _files = null;
                    }
                }
                else
                {
                    result = "Directory does not exist";
                }
            }
            catch (System.Exception) { throw; }

            return(result);
        }
Ejemplo n.º 3
0
        public string ListFiles(string dir, string ext, bool doSubFolders = false)
        {
            string     result = string.Empty;
            FileLister _files;

            try
            {
                if (System.IO.Directory.Exists(dir))
                {
                    if (ext.Length < 3)
                    {
                        result = "Invalid extension (3 characters are required)";
                    }
                    else
                    {
                        _files = new FileLister(ext, dir, doSubFolders);

                        if (_files.count < 1)
                        {
                            result = "No Files Found";
                        }
                        else
                        {
                            StringBuilder str = new StringBuilder();

                            foreach (FileDetail x in _files.CurrentFiles)
                            {
                                str.Append(x.FilePath).Append("|").Append(x.FileName).Append(",");
                            }

                            char[] charsToTrim = { ',', '|', ' ', '.' };
                            result = str.ToString().TrimEnd(charsToTrim);
                        }

                        _files = null;
                    }
                }
                else
                {
                    result = "Directory does not exist";
                }
            }
            catch (System.Exception) { throw; }

            return(result);
        }