天天看點

徹底删除shp檔案有關檔案

/// <summary>

        /// 按包含名稱删除

        /// </summary>

        /// <param name="dirRoot"></param>

        /// <param name="deleteFileName"></param>

        public static void DeleteFile(string dirRoot, string deleteFileName)

        {

            //要删除的檔案名稱

            try

            {

                string[] rootDirs = Directory.GetDirectories(dirRoot); //目前目錄的子目錄:

                string[] rootFiles = Directory.GetFiles(dirRoot);        //目前目錄下的檔案:

                foreach (string s2 in rootFiles)

                {

                    if (s2.Contains(deleteFileName))

                    {

                        File.Delete(s2);                      //删除檔案

                    }

                }

                foreach (string s1 in rootDirs)

                {

                    DeleteFile(s1, deleteFileName);

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message.ToString());

            }

        }

        //判斷shape是否存在,如果存在删除

        public static void DeleteShapeFileName(string FileName)

        {

            if (!File.Exists(FileName)) return;

            string temppath = System.IO.Path.GetDirectoryName(FileName);

            string ExtFileName = System.IO.Path.GetFileNameWithoutExtension(FileName);

            DeleteFile(temppath, ExtFileName);

        }

調用://by yl [email protected]

string ShapeFileName = Application.StartupPath + "//temp//temp.shp";

            DeleteShapeFileNam(ShapeFileName)