2013-05-21 124 views
-7
    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 我添加了删除文件的功能,但我怎样才能改变它在??? THX柠了... dfsdfds ˚F dsfsdfsdfsd fsdfds如何删除一个目录递归

+3

请详细说明“不工作”。 – tnw

+0

我只是删除文件而不是文件夹 – piter

+2

什么tnw说,你的“删除”甚至有一个评论说,它用于删除文件不是目录? – Sayse

回答

6

试试这个

Directory.Delete(topPath, true); 

第二个参数表示 - 删除会recurcive。

+0

Bartdude,我该怎么做? – piter

+1

@piter - 您拥有所需的一切,以实现您提供的代码所需的内容。 –