|
I´m trying to tell the path that there are only subfolder that it gonna countfiles and pass subfolder name insted for path name and path filescount...
my code works but i want to change that it only will look in subfolders..
And i think my Debug are broke beacause i get error when i use Directory.MoveTo(sub, dest) strange.. says that this file allready exists in dest..
Thanks..!;P
|
|
|
|
|
The number of files contained in all subdirectories of a given folder?
string path = @"C:\";
string[] subDirs = System.IO.Directory.GetDirectories(path);
int count = 0;
for (int i = 0; i < subDirs.Length; i++)
count += System.IO.Directory.GetFiles(subDirs[i]).Length;
Please improve your English -- it was very hard for me to understand you.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
ok =) gonna try...
Way won´t this work??
System.IO.DirectoryInfo subDI = new System.IO.DirectoryInfo(path);
foreach (String sub in Directory.GetDirectories(path))
{
foreach (String file in Directory.GetFiles(sub, "*.dat"))
{
int count = 0; for (int i = 0; i < sub.Length; i++) count += System.IO.Directory.GetFiles(sub[i]).Length; //// Here!!!!
String subName = sub.Substring(sub.LastIndexOf(@"\") + 1);
DateTime time = DateTime.Now;
ListViewItem item = new ListViewItem(new string[] { sort, subName, time.ToString(), "", count.ToString(), "", pris, appl });
this.listView2.Items.Add(item);
this.listView2.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
this.toolStripProgressBar1.Value += 50;
sparaform();
}
this.toolStripProgressBar1.Value = 0;
}
Want to getfiles count from subfolder to the path.
//thanks man!
|
|
|
|
|
Please read a documentation of foreach statement in msdn.
List<string> result = new List<string>();
foreach (String sub in Directory.GetDirectories(path)) {
int count = 0;
foreach (string subSub in Directory.GetDirectories(sub))
count += Directory.GetFiles(subSub).Length;
string subName = Path.GetFileName(sub);
result.Add(subName + ": " + count.ToString() + " files in subdirectories");
}
-- modified at 8:17 Monday 17th September, 2007
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
tnx man.. but i did like this:
System.IO.DirectoryInfo subDI = new System.IO.DirectoryInfo(path);
foreach (String sub in Directory.GetDirectories(path))
{
foreach (String file in Directory.GetFiles(sub, "*.dat"))
{
listView2.Items.Clear();
this.toolStripProgressBar1.Value += 10;
System.Threading.Thread.Sleep(dimension);
int fileCount = System.IO.Directory.GetFiles(sub, "*.*", SearchOption.AllDirectories).Length;
String subName = sub.Substring(sub.LastIndexOf(@"\") + 1);
DateTime time = DateTime.Now;
ListViewItem item = new ListViewItem(new string[] { sort, subName, time.ToString(), "", fileCount.ToString(), "", pris, appl });
this.listView2.Items.Add(item);
ListViewItem item2 = new ListViewItem(new string[] { sort, subName, time.ToString(), "", fileCount.ToString(), "", pris, appl });
this.listView3.Items.Add(item2);
works just fine.. yet..=)
But i got another problem:
i start a timer with button1 and want to stop it with button2
i thought it could be like this:
private void button1_Click(object sender, EventArgs e)
{
string[] lines1 = System.IO.File.ReadAllLines("inställningar.txt");
string path1 = lines1[8];
string tid = lines1[0];
int dimension = Convert.ToInt32(tid);
Timer oT = new Timer();
oT.Tick += new System.EventHandler(TimerFunction);
oT.Interval = dimension;
oT.Start();
}
private void button2_Click(object sender, EventArgs e)
{
Timer oT = new Timer();
oT.Tick += new System.EventHandler(Timerfunction);
oT.Stop();
}
But i where wrong!! How would u do it??
tnx!;)
|
|
|
|
|
Sorry for complaining... could you modify your post and enclose code blocks with "pre" tags? e.g. <pre>some code</pre> ?
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
You should revise your knowledge about variable visibility and their life time.
void A()
{
string str = new string();
str = "text";
}
void B()
{
string str = new string();
Console.WriteLine(str);
}
To stop a timer you must not declare it as a local variable.
Timer oT = new Timer();
private void button1_Click(object sender, EventArgs e)
{
string[] lines1 = System.IO.File.ReadAllLines("inställningar.txt");
string path1 = lines1[8];
string tid = lines1[0];
int dimension = Convert.ToInt32(tid);
oT.Interval = dimension;
oT.Start();
}
private void button2_Click(object sender, EventArgs e)
{
oT.Tick -= TimerFunction;
oT.Stop();
}
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Hi everybody!
I have encountered a strange (and annoying) problem. The project runs fine and compiles correctly, however I have much code in the one file. I would like to split it. Unfortunately, if I move a class to a new file, then I get CS0234 error at each reference to this class in the original file:
"The type or namespace XXX name could not be found (are you missing a using directive or an assembly reference?)"
WTH is going on? Please help!
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
In the same project?
Is it still in the same namespace?
If you use using directives, are they in the second file too?
|
|
|
|
|
Yes, the same project and the same namespace. The code looks like this:
Variant 1. (working):
namespace X
{
class A
{
}
class B : A
{
}
class C
{
A someMember;
}
}
Variant 2. (failed to compile):
namespace X
{
class A
{
}
}
namespace X
{
class B : A
{
}
class C
{
A someMember;
}
}
I also noticed this:
I have a solution with a number of projects in it. When I try to compile only the project with the code above (moreless...), everything goes O.K. But when I try to compile the whole solution (or any of the rest of projects which are dependent on the ABC library), I get these errors. Huh?
Looking forward for some help... :]
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
I don't know. That second one compiles for me. It only gives
warning CS0169: The private field 'X.C.someMember' is never used
|
|
|
|
|
Is the split out file being compiled?
|
|
|
|
|
Hard to say!
If I COPY the class to a new file then I get error:
"The namespace 'X' already contains a definition for 'Y'".
But if I MOVE (or delete the original one) the class then I get a bunch of "could not be found".
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
|
One more:
using X.Y;
namespace X
{
}
namespace X.Y
{
}
It looks like the file isn't included in the project anyway or sth like that
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
One more remark:
These moved classes/namespaces ARE present in the Intellisense....
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Hello
How can i let the user chose the sever and the DataBase when the project is open
i mean how i can give the user the "Add Connection form" as he do when he want to Add Connection to the project,
he choose server and connect to the database so the form appear.
this what i want to do but by code and take the server name and the databas name from the Add Connection Form.
Thanks in advance
Assaf
|
|
|
|
|
|
Anyway Thank you for your help ...
Assaf
|
|
|
|
|
There is no one particular right way to do this. Like PIEBALD said, you'll have to create your own. Shouldn't be the tough. You'll need to have a way to store locally on the client machine the different connections, and other pertinent information needed for the connections.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I can do my own
But i want to call the one is called by the wizard where i choose the server and the database
and i can retreive then the name of each
My question can i do this by code ???
Thank you in advance
Assaf
|
|
|
|
|
Assaf82 wrote: i want to call the one is called by the wizard
Not sure if you can. It might be easier just to do your own
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
If it's even possible, the user would need to have Visual Studio installed to use your program.
---
single minded; short sighted; long gone;
|
|
|
|
|
Or will something like this help?
System.IO.FileInfo f = new System.IO.FileInfo ( "\\xt.udl" ) ;
f.OpenWrite().Close() ;
System.Diagnostics.Process p = System.Diagnostics.Process.Start ( "\\xt.udl" ) ;
p.WaitForExit() ;
System.Console.Write ( f.OpenText().ReadToEnd() ) ;
|
|
|
|
|
hi
How does one populate a grid with an array of objects?
this is the code for populatin a dropdown list control.
Author[] authorArray = dbComponent.GetAuthors();<br />
<br />
foreach (Author a in authorArray)<br />
{<br />
ListItem item = new ListItem();<br />
item.Text = a.FirstName + " " + a.LastName;<br />
item.Value = a.AuthorID;<br />
ddlAuthor.Items.Add(item);<br />
}
but i want to populate a grid control...
could anyone please help.
Thanks
|
|
|
|