如何在保存之前重命名文件 [英] How to rename file before saving

查看:174
本文介绍了如何在保存之前重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将文件复制到另一个文件夹我想在保存到目标文件夹之前更改该文件的名称

i am使用此代码进行复制



 OpenFileDialog op1 =  new  OpenFileDialog(); 
op1.Multiselect = true ;
op1.ShowDialog();
op1.Filter = allfiles | * .txt;
textBox1.Text = op1.FileName;

int count = 0 ;
string [] FName;
foreach string s in op1.FileNames)
{
FName = s.Split(' \\' );
// FileInfo fInfo = new FileInfo(textBox1.Text);
< span class =code-comment> //
fInfo.MoveTo(Macadd.Text);

File.Copy( s, \\\\00.3.10.11 \\FileDump \\ + FName [FName.Length - 1 ]);


count ++;
}
MessageBox.Show(Convert.ToString(count)+ 文件已成功保存< /跨度>);

解决方案

使用 File.Move [ ^ ]


  string  a; 
a =(Macadd.Text + .txt);
File.Copy(s, \\\\100.43.100.101 \\ FileDump \\ + a); // + FName [FName.Length - 1]) ;
count ++;
}


希望此链接对您重命名文件很有用。



http://stackoverflow.com/questions/680786/ rename-files-name-in-a-folder / 680802#680802 [ ^ ]





--SDK

I have to copy a file to another folder i want to change the name of that file before saving to destination folder
i am using this code for copying

OpenFileDialog op1 = new OpenFileDialog();
           op1.Multiselect = true;
           op1.ShowDialog();
           op1.Filter = "allfiles|*.txt";
           textBox1.Text = op1.FileName;

           int count = 0;
           string[] FName;
           foreach (string s in op1.FileNames)
           {
               FName = s.Split('\\');
               //FileInfo fInfo = new FileInfo(textBox1.Text);
               //fInfo.MoveTo(Macadd.Text);

               File.Copy(s, "\\\\100.3.10.11\\FileDump\\" + FName[FName.Length - 1]);


               count++;
           }
           MessageBox.Show(Convert.ToString(count) + " File Saved Successfully ");

解决方案

Use File.Move[^]


string a;
            a = (Macadd.Text + ".txt");
            File.Copy(s, "\\\\100.43.100.101\\FileDump\\" + a);//+ FName[FName.Length - 1]);
            count++;
        }


Hope this link will useful for you for renaming files.

http://stackoverflow.com/questions/680786/rename-files-name-in-a-folder/680802#680802[^]


--SDK


这篇关于如何在保存之前重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆