Пример #1
0
    static void Main()
    {
        //Run through once to make sure the basics work
            FileHelper fh = new FileHelper();
            fh.setPath("D:\\Music");
            Console.WriteLine(fh.getPath());
            //Search sub directories
            //string[] extensions = new[] { ".jpg", ".tiff", ".bmp" };
            string[] extensions = new[] { ".mp3" };
            string[] files = fh.findfiles(extensions,true);
            Console.WriteLine("Number of Files: "+files.Length);
            Console.WriteLine("File Names:");
            foreach (string fname in files)
            {
                Console.WriteLine(fname);
            }

            /*******Now lets try and break this***********/
            //Try an invalid Path
            try
            {
                fh.setPath("Q:\\Music");//Q drive does not exist
            }
            catch (ArgumentException e)
            {
                Console.WriteLine("Crisis averted:" + e.Message);
            }
            //Try an empty string
            try
            {
                fh.setPath(""); //throwing over an empty path
            }
            catch (ArgumentException e)
            {
                Console.WriteLine("Crisis averted:" + e.Message);
            }
            //Try an empty extension
            try
            {
                fh.setPath("D:\\Music"); //use a normal path again
                files = fh.findfiles(null, true); //null the extensions
            }
            catch (ArgumentException e)
            {
                Console.WriteLine("Crisis averted:" + e.Message);
            }
    }