get files one by one in the lable
-
hello every body i want to get the file list one by one in a lable giving path of the folder of the file using this code but it does not work for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++) { object[] file=Directory.GetFiles(textBox1.Text+@"\"); label2.Text = file[i].ToString(); } can any body explain me
-
hello every body i want to get the file list one by one in a lable giving path of the folder of the file using this code but it does not work for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++) { object[] file=Directory.GetFiles(textBox1.Text+@"\"); label2.Text = file[i].ToString(); } can any body explain me
as i understand you want to write all dir. in label, try this: for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++) { object[] file=Directory.GetFiles(textBox1.Text+@"\"); label2.Text += file[i].ToString()+"\n"; } or arraylist a=new arraylist(); for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++) { object[] file=Directory.GetFiles(textBox1.Text+@"\"); //label2.Text += file[i].ToString()+"\n"; a.add(file[i].ToString()); }
-
as i understand you want to write all dir. in label, try this: for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++) { object[] file=Directory.GetFiles(textBox1.Text+@"\"); label2.Text += file[i].ToString()+"\n"; } or arraylist a=new arraylist(); for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++) { object[] file=Directory.GetFiles(textBox1.Text+@"\"); //label2.Text += file[i].ToString()+"\n"; a.add(file[i].ToString()); }
thanks sir but exactly what i need is the files name of the dir. is just kike the anti virus file scane looks that is file name and the path is showing in the lable might be using timerin it private void button1_Click(object sender, EventArgs e) { timer1.Start(); timer1.Interval = 2000; } private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++) { object[] file=Directory.GetFiles(textBox1.Text+@"\"); label2.Text = file[i].ToString(); } timer1.Stop(); } whatis the problem in it this shows only the last file of the dir.
-
thanks sir but exactly what i need is the files name of the dir. is just kike the anti virus file scane looks that is file name and the path is showing in the lable might be using timerin it private void button1_Click(object sender, EventArgs e) { timer1.Start(); timer1.Interval = 2000; } private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++) { object[] file=Directory.GetFiles(textBox1.Text+@"\"); label2.Text = file[i].ToString(); } timer1.Stop(); } whatis the problem in it this shows only the last file of the dir.
sorry are you trying to make anti virus program
-
sorry are you trying to make anti virus program
-
thanks sir but exactly what i need is the files name of the dir. is just kike the anti virus file scane looks that is file name and the path is showing in the lable might be using timerin it private void button1_Click(object sender, EventArgs e) { timer1.Start(); timer1.Interval = 2000; } private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++) { object[] file=Directory.GetFiles(textBox1.Text+@"\"); label2.Text = file[i].ToString(); } timer1.Stop(); } whatis the problem in it this shows only the last file of the dir.
tanweer akhtar wrote:
for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++) { object[] file=Directory.GetFiles(textBox1.Text+@"\"); label2.Text = file[i].ToString(); } timer1.Stop(); }
Yes, it will show only the last file in the list. Try replacing:
label2.Text = file[i].ToString();
with
label2.Text += file[i].ToString();
as this means the new name will be appended to the existing text, rather than replacing it. You will also want to clear the label2.Text before entering the for loop, and add a newline to the end of the name (or they will all run together in one big line). Other improvements you may want to do: 1) Change the label for a ListBox - it is better designed for showing lists than a label. 2) Consider using foreach rather than your existing for loop:
DirectoryInfo dir = new DirectoryInfo(dirname); foreach (FileInfo fi in dir.GetFiles()) { string filename = fi.FullName; ... }
All those who believe in psycho kinesis, raise my hand. My :badger:'s gonna unleash hell on your ass. :badger:tastic!
-
No sir i just try to make a file counter in my program that it------------->>>>>>>>>>>>>>> can u hepl me..........>>>>>>>>>>>>>>>
for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++) { object[] file=Directory.GetFiles(textBox1.Text+@"\"); for(int x=0;x