如何递归删除目录

时间:2013-05-21 15:17:02

标签: c#

                 case "PWD":
                        //    Form1.ClientConnect(ClientID, clientMsg);
                            SendUpdate(ClientID + " : " + clientMsg);
                            SendMsg("257 " + "\"" + PresentDirOnFTP + "\"" + " is current directory \r\n", ref outBuffer);
                            break;
                 case "DELE":
                            //Delete the file from the Server and reply back.
                            Form1.ClientConnect(ClientID, clientMsg);
                            SendUpdate(ClientID + " : " + clientMsg);
                            clientMsg = clientMsg.Substring(4).Trim();

                            SendMsg(DeleteFileForServer(rootDirOnSystem, PresentDirOnFTP, clientMsg), ref outBuffer);
                            break;
         private string DeleteFileForServer(string rootDirOnServer, string PresentDirOfFTP, string fileName)
    {
        //check for seperator
        Thread oThread = Thread.CurrentThread;
        lock (oThread)
        {
            string root = FilePath(rootDirOnServer, PresentDirOfFTP, fileName);
            try
            {
                FileInfo oFile = new FileInfo(root);
                if (oFile.FullName != "")
                {
                    oFile.Delete();
                    return "250 delete command successful\r\n";
                }
            }
            catch (FileNotFoundException e)
            {
                //Form1.ClientConnect(ClientID, e.ToString());
                SendUpdate(ClientID + " : " + e.ToString());
                return "550 file not found, or no access.\r\n";
            }
            catch (IOException e)
            {
               // Form1.ClientConnect(ClientID, e.ToString());
                SendUpdate(ClientID + " : " + e.ToString());
                return "550 file not found, or no access.\r\n";
            }
           // Form1.ClientConnect(ClientID, "Error in Deleteing file " + fileName);
            SendUpdate(ClientID + " : " + "Error in Deleteing file " + fileName);
            return "550 file not found, or no access.\r\n";
        }
    }

如何使用命令DELE从服务器递归删除文件夹?我试过但不工作...... thx 我添加了删除文件的功能,但我怎么能改变它? 很多...... dfsdfds F dsfsdfsdfsd fsdfds

1 个答案:

答案 0 :(得分:6)

试试这个

Directory.Delete(topPath, true);

第二个参数表示 - 删除将是递归的。