Hello I would like to be able to change the text of my txtFiles textbox at each iteration of files when there are several files.
And also be able to copy only one file at a time when I want it even if there are several files in the directory.
I declared the textchanged event. I have declared the txtFiles_TextChanged function but I don't know what to put in it to make the text of the txtFiles textbox change with each iteration of files.
I declared txtFiles.Text = ConvertToString (files [i]); to change the text in the textbox.
I would also like to be able to copy only one file at a time but it wipes out all the txt files.
How do you resolve this?
string sourceDir =
@"C:\Users\PORTABLEHP\Documents";
string destDir =
@"C:\Users\PORTABLEHP\Documents\
xgen";
public évent EventHandler
textchanged;
private void btnCopy(object
sender,EventArgs e)
{
try
{
string [] txtList = Directory.
GetFiles(sourceDir,"*.txt");
foreach(string f in txtList)
{
try
{
string fName = f.Substring
(sourceDir.Length + 1);
string [] files = new string
[sourceDir.Length];
progressBar1.Value = 1;
progressBar1.Minimum = 0;
progressBar1.Maximum =
files.Length;
for(int i = 1;i < files.Length;
i++)
{
progressBar1.PerformStep();
//To have the text change from the
textbox
txtFiles.Text = ConvertToString
(files[i]);
File.Copy(Path.Combine
(sourceDir,fName), Path.Combine
(destDir,fName), true);
}
}
catch(IOException copyerror)
{
MessageBox.Show(copyerror.Message);
}
}
}
catch (DirectoryNotFoundException
dirnotfound)
{
MessageBox.Show
(dirnotfound.Message);
private void txtFiles_TextChanged
(object sender,EventArgs e)
{
// I don't know ?
}
So if I got you right, you need to do a little change in your code
Change
txtFiles.Text = ConvertToString(files[i]);
To
txtFiles.Text = $"{ Path.GetFileName(f)} was copied"; //f was declared as string in your first loop that contains the file path
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.