Esempio n. 1
0
        public void DirSearch(string dir)
        {
            try
            {
                foreach (string file in Directory.GetFiles(dir))
                {
                    // For every file
                    try
                    {
                        FileInfo info     = new FileInfo(file);
                        string   fileName = Path.GetFileName(file);
                        foreach (Regex Re in regexes)
                        {
                            // If it is a Doc/Docx file
                            if (Re.Match(fileName).Success)
                            {
                                // If the size is > #
                                long fileLength = info.Length;
                                Console.WriteLine(fileLength.ToString());
                                if (max > fileLength)
                                {
                                    // Example:
                                    // If max is 2000000000 and file is 1176776 -> True
                                    // If max is 1000000000 and file is 1176776 -> False
                                    try
                                    {
                                        // Delete the file
                                        File.Delete(file);
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        continue;
                    }
                }

                foreach (string d in Directory.GetDirectories(dir))
                {
                    Console.WriteLine(d);
                    DirSearch(d);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 2
0
            public FileDate(string sFileName)
            {
                Match m = Re.Match(sFileName);

                Year  = Convert.ToInt32(m.Groups[1].Value);
                Month = Convert.ToInt32(m.Groups[2].Value);
                Day   = Convert.ToInt32(m.Groups[3].Value);

                if (!string.IsNullOrWhiteSpace(m.Groups[5].Value))
                {
                    FileNo = Convert.ToInt32(m.Groups[5].Value);
                }
            }             // constructor