Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
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
JokeRe: Ho to assign a numbering system to the file system hierarchy Pin
PIEBALDconsult25-Sep-14 14:02
mvePIEBALDconsult25-Sep-14 14:02 
GeneralRe: Ho to assign a numbering system to the file system hierarchy Pin
SledgeHammer0125-Sep-14 15:06
SledgeHammer0125-Sep-14 15:06 
AnswerRe: Ho to assign a numbering system to the file system hierarchy PinPopular
Freak3025-Sep-14 22:00
Freak3025-Sep-14 22:00 
SuggestionRe: Ho to assign a numbering system to the file system hierarchy Pin
Richard Deeming26-Sep-14 1:14
mveRichard Deeming26-Sep-14 1:14 
GeneralRe: Ho to assign a numbering system to the file system hierarchy Pin
BillWoodruff26-Sep-14 1:22
professionalBillWoodruff26-Sep-14 1:22 
AnswerRe: Ho to assign a numbering system to the file system hierarchy Pin
BillWoodruff26-Sep-14 1:21
professionalBillWoodruff26-Sep-14 1:21 
QuestionHow to extract VBA code from Excel in Visual Studio and read it as text with c#? Pin
Member 1110881725-Sep-14 0:01
Member 1110881725-Sep-14 0:01 
AnswerRe: How to extract VBA code from Excel in Visual Studio and read it as text with c#? Pin
Eddy Vluggen25-Sep-14 2:19
professionalEddy Vluggen25-Sep-14 2:19 
AnswerRe: How to extract VBA code from Excel in Visual Studio and read it as text with c#? Pin
Chris Quinn25-Sep-14 4:41
Chris Quinn25-Sep-14 4:41 
QuestionRecevoir des mails Pin
Member 1110858924-Sep-14 23:51
Member 1110858924-Sep-14 23:51 
SuggestionRe: Recevoir des mails Pin
George Jonsson25-Sep-14 0:07
professionalGeorge Jonsson25-Sep-14 0:07 
GeneralRe: Recevoir des mails Pin
Member 1110858925-Sep-14 0:34
Member 1110858925-Sep-14 0:34 
GeneralRe: Recevoir des mails Pin
Richard MacCutchan25-Sep-14 0:45
mveRichard MacCutchan25-Sep-14 0:45 
AnswerRe: Recevoir des mails Pin
Wayne Gaylard25-Sep-14 0:46
professionalWayne Gaylard25-Sep-14 0:46 
SuggestionRe: Recevoir des mails Pin
Richard Deeming25-Sep-14 2:32
mveRichard Deeming25-Sep-14 2:32 
GeneralRe: Recevoir des mails Pin
Wayne Gaylard25-Sep-14 2:36
professionalWayne Gaylard25-Sep-14 2:36 
AnswerRe: Recevoir des mails Pin
George Jonsson25-Sep-14 0:43
professionalGeorge Jonsson25-Sep-14 0:43 

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.