NetHadoop.FSClient.ReName C# (CSharp) Method

ReName() public method

public ReName ( string oldPath, string newPath ) : bool
oldPath string
newPath string
return bool
        public bool ReName(string oldPath,string newPath)
        {
            TBufferedTransport tsport = null;
               ThriftHadoopFileSystem.Client client = Connect(out tsport);
               bool result = false;
               if (client != null)
               {
               Pathname pn=new Pathname() { pathname = oldPath };
               if (client.exists(pn))//如果存在才执行
                   result = client.rename(pn, new Pathname() { pathname = newPath });

               tsport.Close();
               }
               return result;
        }

Usage Example

示例#1
0
        //重命名
        private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.Label))
            {
                ListViewItem myItem = lvFiles.Items[e.Item];
                if (myItem != null)
                {
                    ListViewItem existItem = FindItemByName(e.Label);
                    if (existItem != null)
                    {
                        MessageBox.Show("该文件夹名已存在!");
                        e.CancelEdit = true;
                    }
                    else
                    {
                        FSClient   client = new FSClient();
                        FileStatus myFile = myItem.Tag as FileStatus;

                        bool result = client.ReName(myFile.Path, ConfigHelper.HdfsRoot + "/" + CurrentPath + e.Label);
                        if (!result)
                        {
                            e.CancelEdit = true;
                            MessageBox.Show("文件夹重命名失败!");
                        }
                        else
                        {
                            LoadFileStatus(CurrentPath);
                        }
                    }
                }
            }
        }
All Usage Examples Of NetHadoop.FSClient::ReName