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

C#

 
AnswerRe: Getting a directory path if directory name is given Pin
Richard MacCutchan11-Apr-18 3:32
mveRichard MacCutchan11-Apr-18 3:32 
GeneralRe: Getting a directory path if directory name is given Pin
NiKHiLMS11-Apr-18 21:38
NiKHiLMS11-Apr-18 21:38 
GeneralRe: Getting a directory path if directory name is given Pin
Jochen Arndt11-Apr-18 22:37
professionalJochen Arndt11-Apr-18 22:37 
GeneralRe: Getting a directory path if directory name is given Pin
NiKHiLMS11-Apr-18 22:51
NiKHiLMS11-Apr-18 22:51 
GeneralRe: Getting a directory path if directory name is given Pin
Jochen Arndt12-Apr-18 0:01
professionalJochen Arndt12-Apr-18 0:01 
AnswerRe: Getting a directory path if directory name is given Pin
MadMyche11-Apr-18 5:04
professionalMadMyche11-Apr-18 5:04 
GeneralRe: Getting a directory path if directory name is given Pin
NiKHiLMS11-Apr-18 21:39
NiKHiLMS11-Apr-18 21:39 
AnswerRe: Getting a directory path if directory name is given Pin
#realJSOP12-Apr-18 1:25
mve#realJSOP12-Apr-18 1:25 
// folder names you do not want to search
private static List<string> BadNames = new List<string>{"Adobe","CPMigrator","ServicePack","Symantec", "Server", "TumbleWeed"};
// folder name you're looking for
private static string targetFolder = "Common7";

static void Main(string[] args)
{
    // start searching in the specified path, and get all of the subfolders therein
    List<string> folders = GetFolders(@"C:\Program Files\");
    // find the first path that ends with the target folder name
    // (of course, you can use pretty much any process for finding the path you're 
    // interested in, so the code I use below should be seen as merely an example).
    string found = folders.FirstOrDefault(x=>x.ToUpper().EndsWith(targetFolder.ToUpper()));
}

// recursive method to build a list of folders
public static List<string> GetFolders(string path)
{
    List<string> folders = new List<string>();
    foreach(string bad in BadNames)
    {
        if (path.ToUpper().Contains(bad.ToUpper())) 
        {
            return folders;
        }
    }

    try
    {
        folders = Directory.GetDirectories(path, "*.*", SearchOption.TopDirectoryOnly).ToList();
        for (int i = 0; i <folders.Count; i++)
        {
            folders.AddRange(GetFolders(folders[i]));
        }
    }
    // this catch block allows you to bypass folders that you don't have access to
    catch (Exception)
    {
    }
    return folders;
}

".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013


modified 13-Apr-18 9:41am.

Generalstring Pin
Baymediasoft technologies11-Apr-18 0:11
professionalBaymediasoft technologies11-Apr-18 0:11 
GeneralRe: string Pin
OriginalGriff11-Apr-18 0:26
mveOriginalGriff11-Apr-18 0:26 
GeneralRe: string Pin
Richard MacCutchan11-Apr-18 1:44
mveRichard MacCutchan11-Apr-18 1:44 
GeneralRe: string Pin
OriginalGriff11-Apr-18 1:51
mveOriginalGriff11-Apr-18 1:51 
QuestionC# Integrating With Skype Pin
Gavin Coates10-Apr-18 9:45
Gavin Coates10-Apr-18 9:45 
AnswerRe: C# Integrating With Skype Pin
Richard MacCutchan10-Apr-18 11:08
mveRichard MacCutchan10-Apr-18 11:08 
GeneralRe: C# Integrating With Skype Pin
Gavin Coates11-Apr-18 3:13
Gavin Coates11-Apr-18 3:13 
AnswerRe: C# Integrating With Skype Pin
Gerry Schmitz10-Apr-18 11:21
mveGerry Schmitz10-Apr-18 11:21 
Questionexcel udf returns only the first column name in order to display a two dimentional array Pin
Gtari Abir10-Apr-18 6:16
Gtari Abir10-Apr-18 6:16 
AnswerRe: excel udf returns only the first column name in order to display a two dimentional array Pin
Richard Andrew x6410-Apr-18 6:57
professionalRichard Andrew x6410-Apr-18 6:57 
AnswerRe: excel udf returns only the first column name in order to display a two dimentional array Pin
Luc Pattyn10-Apr-18 13:03
sitebuilderLuc Pattyn10-Apr-18 13:03 
GeneralRe: excel udf returns only the first column name in order to display a two dimentional array Pin
Gtari Abir12-Apr-18 0:13
Gtari Abir12-Apr-18 0:13 
GeneralRe: excel udf returns only the first column name in order to display a two dimentional array Pin
Luc Pattyn12-Apr-18 3:09
sitebuilderLuc Pattyn12-Apr-18 3:09 
QuestionIssues in ajax call in MVC Pin
Dhyanga9-Apr-18 5:41
Dhyanga9-Apr-18 5:41 
AnswerRe: Issues in ajax call in MVC Pin
Dhyanga9-Apr-18 6:50
Dhyanga9-Apr-18 6:50 
QuestionSyntax of creating the following matrix in C# Pin
Shibe19959-Apr-18 1:00
Shibe19959-Apr-18 1:00 
AnswerRe: Syntax of creating the following matrix in C# Pin
Gerry Schmitz9-Apr-18 2:27
mveGerry Schmitz9-Apr-18 2:27 

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.