Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
QuestionRe: XSD question... Pin
George Jonsson27-Sep-14 3:55
professionalGeorge Jonsson27-Sep-14 3:55 
AnswerRe: XSD question... Pin
SledgeHammer0127-Sep-14 6:26
SledgeHammer0127-Sep-14 6:26 
AnswerRe: XSD question... Pin
George Jonsson27-Sep-14 13:21
professionalGeorge Jonsson27-Sep-14 13:21 
GeneralRe: XSD question... Pin
SledgeHammer0127-Sep-14 14:21
SledgeHammer0127-Sep-14 14:21 
GeneralRe: XSD question... Pin
George Jonsson27-Sep-14 15:13
professionalGeorge Jonsson27-Sep-14 15:13 
GeneralRe: XSD question... Pin
SledgeHammer0127-Sep-14 16:00
SledgeHammer0127-Sep-14 16:00 
GeneralRe: XSD question... Pin
George Jonsson27-Sep-14 20:21
professionalGeorge Jonsson27-Sep-14 20:21 
GeneralRe: XSD question... Pin
SledgeHammer0128-Sep-14 7:10
SledgeHammer0128-Sep-14 7:10 
QuestionRecommendations on VB.Net to C# code conversion tool Pin
Vipul Mehta26-Sep-14 8:31
Vipul Mehta26-Sep-14 8:31 
QuestionRe: Recommendations on VB.Net to C# code conversion tool Pin
Richard MacCutchan26-Sep-14 10:16
mveRichard MacCutchan26-Sep-14 10:16 
QuestionRe: Recommendations on VB.Net to C# code conversion tool Pin
Vipul Mehta26-Sep-14 10:23
Vipul Mehta26-Sep-14 10:23 
AnswerRe: Recommendations on VB.Net to C# code conversion tool Pin
Richard MacCutchan26-Sep-14 21:27
mveRichard MacCutchan26-Sep-14 21:27 
AnswerRe: Recommendations on VB.Net to C# code conversion tool Pin
Ravi Bhavnani28-Sep-14 4:17
professionalRavi Bhavnani28-Sep-14 4:17 
AnswerRe: Recommendations on VB.Net to C# code conversion tool Pin
Simon_Whale28-Sep-14 8:29
Simon_Whale28-Sep-14 8:29 
AnswerRe: Recommendations on VB.Net to C# code conversion tool Pin
Sibeesh KV29-Sep-14 19:10
professionalSibeesh KV29-Sep-14 19:10 
Questionhow to assign listbox value to datagridview in c# Pin
Member 413595226-Sep-14 5:06
Member 413595226-Sep-14 5:06 
AnswerRe: how to assign listbox value to datagridview in c# Pin
Eddy Vluggen26-Sep-14 5:51
professionalEddy Vluggen26-Sep-14 5:51 
AnswerRe: how to assign listbox value to datagridview in c# Pin
ChintanShukla29-Sep-14 23:22
professionalChintanShukla29-Sep-14 23:22 
QuestionNeither validators nor Validationsummery is working Pin
demoninside926-Sep-14 0:50
demoninside926-Sep-14 0:50 
AnswerMy Vote of 1 Pin
Keith Barrow26-Sep-14 1:57
professionalKeith Barrow26-Sep-14 1:57 
AnswerRe: Neither validators nor Validationsummery is working Pin
Eddy Vluggen26-Sep-14 5:54
professionalEddy Vluggen26-Sep-14 5:54 
GeneralRe: Neither validators nor Validationsummery is working Pin
demoninside926-Sep-14 19:34
demoninside926-Sep-14 19:34 
GeneralRe: Neither validators nor Validationsummery is working Pin
Richard MacCutchan26-Sep-14 21:38
mveRichard MacCutchan26-Sep-14 21:38 
GeneralRe: Neither validators nor Validationsummery is working Pin
Keith Barrow29-Sep-14 22:37
professionalKeith Barrow29-Sep-14 22:37 
QuestionHo to assign a numbering system to the file system hierarchy Pin
Rick450d25-Sep-14 12:41
Rick450d25-Sep-14 12:41 
I have a problem that is doing my head in.

I want to iterate through the local PC folders, including directories, and calculate a numbering system against each folder in the file system hierarchy.

The root folders should calculate as 1,2,3 etc.

If there were three sub-folders in folder one the calculated numbers should be:
1.1, 1.2,1.3

If there were three sub-folders in the sub-folder above then the calculated numbers should be:
1.1.1, 1.1.2, 1.1.3

If there were three sub-folders in folder two (a root folder) the calculated numbers should be:
2.1, 2.2, 2.3

Or expressed in another way:

1 Root Folder
1.1 Root Sub Folder 1
1.1.1 Sub Folder
1.1.2 Sub Folder
1.2 Root Sub Folder 2
1.2.1 List item
1.2.2 List item

etc. etc.

This logic should then be applied to all folders and sub-folders.


Output Example

1.1.1 | "c:\Root\Folder1\Folder1\"


What I have so far appears to work ok in some situations but can fail in other situations:

private string rootpath = @"C:\FolderHierarchy\";
private string FolderSequenceCountBase = "";
private int CurrentRootPathCount = 0;
private int Counter = 0;

private void CalculateFolderHierarchyNumbers()
{
    //Get First List of Folders
    string[] Dirs = Directory.GetDirectories(rootpath, "*.*", SearchOption.TopDirectoryOnly);

    for (int i = 0; i < Dirs.Count(); i++)
    {
        FolderSequenceCountBase = (i + 1).ToString();
        CurrentRootPathCount = i + 1;
        Console.WriteLine("Processed folder '{0}'.", Dirs[i] + " = " + (i + 1));
        GetSubDirs(Dirs[i]);
    }
}

private void GetSubDirs(string item)
{
    //Get next list of folders in the folder hierarchy
    string[] SubDirs = Directory.GetDirectories(item, "*.*", SearchOption.TopDirectoryOnly);
    foreach (var DirPath in SubDirs)
    {
        //Increment count of folders within the current folder list
        Counter += 1;
        Console.WriteLine("Processed folder '{0}'.", DirPath + " = " + FolderSequenceCountBase + "." + Counter);
    }

    Counter = 0;

    //Get next list of folders in the folder hierarchy
    foreach (var DirPath in SubDirs)
    {
        FolderSequenceCountBase += ".1";
        GetSubDirs(DirPath);
    }
}


Hope this is clear.

Thanks
Rick

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.