NetHadoop.FSClient.Delete C# (CSharp) Method

Delete() public method

删除文件或文件夹
public Delete ( string path, bool recursive ) : bool
path string
recursive bool 是否删除子文件夹
return bool
        public bool Delete(string path,bool recursive)
        {
            TBufferedTransport tsport = null;
               ThriftHadoopFileSystem.Client client = Connect(out tsport);
               bool result = false;
               if (client != null)
               {
               Pathname pn = new Pathname() { pathname = path };
               if (client.exists(pn))//如果不存在才执行
                   result = client.rm(pn, recursive);
               tsport.Close();

               }
               return result;
        }

Usage Example

示例#1
0
 //删除选中
 private void btDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("确定删除选中的文件或文件夹?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
         == System.Windows.Forms.DialogResult.Yes)
     {
         if (lvFiles.SelectedItems.Count > 0)
         {
             foreach (ListViewItem item in lvFiles.SelectedItems)
             {
                 FileStatus myfile = item.Tag as FileStatus;
                 if (myfile != null)
                 {
                     FSClient client = new FSClient();
                     bool     result = client.Delete(myfile.Path, true);
                     string   msg    = string.Format("{2}:{0} 删除{1}", Path.GetFileName(myfile.Path), result ? "成功" : "失败", myfile.Isdir ? "文件夹" : "文件");
                     lbProgressTxt.Text = msg;
                 }
                 Application.DoEvents();
             }
             //重新加载
             LoadFileStatus(CurrentPath);
         }
     }
 }
All Usage Examples Of NetHadoop.FSClient::Delete