Пример #1
0
        void mnuRemoveHtmlDocs_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult res = MessageBox.Show("Remove all HTML documents?", "Warning", MessageBoxButton.YesNoCancel);

            if (res != MessageBoxResult.Yes)
            {
                return;
            }

            int cnt      = 0;
            int fail_cnt = 0;

            string[] all_files = Globals.GetAllFiles(Globals.GetCardsPath());
            for (int i = 0; i < all_files.Length; i++)
            {
                FileInfo fi = new FileInfo(all_files[i]);
                if (fi.Extension.ToLower() == ".html")
                {
                    try
                    {
                        File.Delete(all_files[i]);
                        cnt++;
                    }
                    catch (Exception ex)
                    {
                        fail_cnt++;
                        continue;
                    }
                }
            }

            if (fail_cnt == 0)
            {
                string msg = string.Format("Removed Files: {0}", cnt);
                MessageBox.Show(msg);
            }
            else
            {
                string msg = string.Format("Removed Files: {0}, Unremovable Files: {1}", cnt, fail_cnt);
                MessageBox.Show(msg);
            }
        }