Ejemplo n.º 1
0
        private void btnReNameFile2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtFilePath.Text))
            {
                this.lblInfo.Text = "请选择要重命名的文件";
                return;
            }

            if (string.IsNullOrEmpty(this.txtNewName.Text))
            {
                this.lblInfo.Text = "请输入新的名称";
                return;
            }

            try
            {
                FileOperateProxy.ReNameFile(txtFilePath.Text, txtNewName.Text);

                this.lblInfo.Text = "文件重命名成功";
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message.ToString();
            }
        }
Ejemplo n.º 2
0
        private void btnReNameFile_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtFilePath.Text))
            {
                this.lblInfo.Text = "请选择要重命名的文件";
                return;
            }

            if (string.IsNullOrEmpty(this.txtNewName.Text))
            {
                this.lblInfo.Text = "请输入新的名称";
                return;
            }


            string extensName = Path.GetExtension(txtFilePath.Text);
            string filDir     = Path.GetDirectoryName(txtFilePath.Text);

            string newName = filDir + this.txtNewName.Text + extensName;
            int    i       = FileOperateProxy.ReNameFile(txtFilePath.Text, newName, true, ref info);

            if (i != 0)
            {
                this.lblInfo.Text = info;
            }
            else
            {
                this.lblInfo.Text     = "文件重命名成功";
                this.txtFilePath.Text = string.Empty;
                this.txtNewName.Text  = string.Empty;
            }
        }