|
The way you process the sub folders the order will be different from the example list you posted. I would uses the recursive call directly after each processed folder and pass the relevant values. Also Counter should not be global but local to the function. It would then look something like this.
private void GetSubDirs(string parentFolder, string parentNumber)
{
string[] SubDirs = Directory.GetDirectories(parentFolder, "*.*", SearchOption.TopDirectoryOnly);
for (int i = 0; i < SubDirs.Count(); i++)
{
string curNumber = String.Format("{0}.{1}", parentNumber, i + 1);
GetSubDirs(SubDirs[i], curNumber);
}
}
I leave it to you how to call the recursive function from the outside.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Freak30 wrote: i < SubDirs.Count()
No need to use the Count extension method on an array - just use the Length property.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
+5 great answer.
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant
|
|
|
|
|
I worked on this this morning (GMT +7); when I came back home later I saw that Freak30 had posted a good answer, which I am up-voting.
I'll go ahead and post this since it's slightly different from Freak30's useful code:
private string[] SubDirs;
private void GetSubDirs(string currentDirectory, int counter, string currentDirectoryName)
{
DirectoryInfo di = new DirectoryInfo(item);
if (di.Exists)
{
if (di.Attributes.HasFlag(FileAttributes.Hidden)) return;
try
{
SubDirs = Directory.GetDirectories(item, "*.*", SearchOption.TopDirectoryOnly);
foreach(string subDir in SubDirs)
{
counter++;
string iName = sName + "." + counter.ToString();
Console.WriteLine("{0} Processed Sub-Folder {1}", iName, subDir);
GetSubDirs(subDir, 0, iName);
}
}
catch (Exception)
{
return;
}
}
else
{
return;
}
} Note this version takes three parameters for the recursive directory-walk method: the current directory to parse's filepath, an integer for the internal counter which is always passed with the value #0, and the current directory's name.
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant
|
|
|
|
|
This is what I'm trying to do:
Im opening Excel workbook
using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(filepath, false))
{
WorkbookPart wbPart = myDoc.WorkbookPart;
//myDoc.WorkbookPart.VbaProjectPart
Sheet mySheet = wbPart.Workbook.Descendants<sheet>().
Where(s => s.Name == sheetName).FirstOrDefault();
if (mySheet == null) //sheet bestaat niet
{
throw new ArgumentException("sheetName");
}
WorksheetPart wsPart = (WorksheetPart)(wbPart.GetPartById(mySheet.Id));
Worksheet worksheet = wsPart.Worksheet;
and then a lot of stuff is going on, I'm making list of all the functions, checking formulas, saving errors, not really important.
What I want to do next is to call a VBA code from this workbook and be able to read is as text and use some string manipulation stuff to find some thing out (like how long are the used functions or find comments, whatever).
Someone an idea how make this possible? I would be really greatfull..
|
|
|
|
|
Which version of the Excel-file? If it is an XLSX, you can rename it to a zip and extract its contents.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Look at the WorkBook's VBProject.VBComponents objects
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Bonjour
Je programme par Visual Studio 11.0 en C#, je ne suis pas un professionnel.
Je cherche un code simple pour recevoir des mails.
J'ai exploré internet, et tous les articles à ce sujet; j'ai compris qu'il faut installer une "librairy" spéciale POP3 non fournie, mais aucune, qui marche, n'est proposée.
Quelqu'un aurait-il une "dll" ou autre, accompagnée d'un code source qui fonctionne simplement, avec explications
en français ?
Merci d'avance.
Cordialement.
JG
|
|
|
|
|
Maybe use English instead. More people will understand your question.
|
|
|
|
|
Hello
I program Visual Studio 11.0 in c#, I am not a professional.
Looking for a simple code to receive mails.
I explored internet, and all the articles about this; I understood that need to install a "" library "" special not supplied POP3, but none that works, is proposed.
Would someone have one 'dll' or another, accompanied by a source code that works simply, with explanations
in french?
Thanks in advance.
Kind regards.
JG
|
|
|
|
|
|
Mailkit[^] is an excellent .Net library that covers emailing.
Hope this helps.
Everyone dies - but not everyone lives
modified 25-Sep-14 8:35am.
|
|
|
|
|
The hamsters have eaten your link:
https://github.com/jstedfast/MailKit[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for that - fixed ! Damn Hamsters !
Everyone dies - but not everyone lives
|
|
|
|
|
I think finding examples in French will be a bit difficult, unless you have your own forums in France.
I think this article describes what you want to do.
A POP3 Client in C# .NET[^]
|
|
|
|
|
Hi,
I have developed one application in this application I have one System.Timers.Timer. Timer is set with 200 millisecond interval.
Now my problem is elapsed event is not triggered with exact 200 millisecond it takes some extra time.
Is there any solution to get event?
Please help me.
Regard,
Amol
-- modified 25-Sep-14 5:51am.
|
|
|
|
|
Please describe:
1. how you are currently measuring the time of the elapsed event: show the code for this.
2. how far-off from the expected 200 ms. is the time of the elapsed event ?
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant
|
|
|
|
|
|
You do realize that Windows is not a real-time operating system?
You're not going to get a perfect 200ms timer no matter what you do. There is always overhead no matter which timer you're using because of the other few hundred threads on system.
|
|
|
|
|
|
i hard dependency injection can be implemented like constructor injection, getter/setter injection, service locator. i just know the term but not well familiar how to implement it writing code. so anyone can redirect me to good starter article on dependency injection implementation with many ways like constructor injection, getter/setter injection, service locator etc. thanks
tbhattacharjee
|
|
|
|
|
How about starting to do some research on your own before you post these very broad open-ended questions ?
Like: searching CodeProject, and reading relevant articles here ?
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant
|
|
|
|
|
|
I have updated my answer. Please look in to that link.
Please up vote if it helped you
Thanks And Regards
Sibeesh
|
|
|
|
|
I want to make USB Blocker Using vb.net or C# in windows Application.Can anyone help me
|
|
|
|