Click here to Skip to main content
15,889,857 members
Home / Discussions / C#
   

C#

 
GeneralRe: My Vote if 1 Pin
OriginalGriff10-Mar-13 0:56
mveOriginalGriff10-Mar-13 0:56 
GeneralRe: My Vote if 1 Pin
Keith Barrow10-Mar-13 0:58
professionalKeith Barrow10-Mar-13 0:58 
AnswerRe: code wave Pin
Marco Bertschi10-Mar-13 4:34
protectorMarco Bertschi10-Mar-13 4:34 
Questioncompression wave Pin
samir razzak10-Mar-13 0:17
samir razzak10-Mar-13 0:17 
AnswerRe: compression wave Pin
OriginalGriff10-Mar-13 0:56
mveOriginalGriff10-Mar-13 0:56 
AnswerRe: compression wave Pin
Marco Bertschi10-Mar-13 4:35
protectorMarco Bertschi10-Mar-13 4:35 
GeneralRe: compression wave Pin
dusty_dex10-Mar-13 6:13
dusty_dex10-Mar-13 6:13 
Question[Resolved] Searching for a file in multiple directories? Pin
Goaty651099-Mar-13 16:43
Goaty651099-Mar-13 16:43 
Hey Guys, I am kind of looking around at a couple different places for answers here, got some help from some great folks here before so here goes!

I am working on, same project as I have always been working on, just adding more stuff lol. In this project I want to call an ini setting into a combo box. Here's where I am, I can list the directories into a comboBox, and I can read a line from an ini from a single location into a combo box. Now, I need to take this one step further. I need to list that ini setting in the comboBox, from within all those directories. All ini files are named the same thing, but the context is different in the ini field. So basically, I have two pieces two a puzzle figured out, that I need to make fit. Here's an example of what I can do, and what I want it to do.

//I can list the directories into a combo box using this
//Inside the FOLDERS directory are three folders, Folder1, Folder2, and Folder3.
//They are what is displayed in the comboBox.
DirectoryInfo obj = new DirectoryInfo("C:\\Users\\first.last\\Desktop\\Projects\\Test Files\\Folders\\");//you can set your directory path here
DirectoryInfo[] folders = obj.GetDirectories();
comboBox.DataSource = folders; // Populate combobox

Ok, so that's simple enough. What I want to do is take the values of my choice from the code below and list them from EACH directory into the comboBox. There could be any numbers of folders in that directory, but that shouldn't matter.

Here is how I show my ini settings now

IniFile ini = new IniFile("C:\\Users\\first.last\\Desktop\\Projects\\Test Files\\Folders\\Folder1\\Settings.txt");
comboBox.Text = ini.IniReadValue("Info", "Name");

Here's what I WANT to be populated in the comboBox at time of load.

IniFile ini = new IniFile("C:\\Users\\first.last\\Desktop\\Projects\\Test Files\\Folders\\" + Search.All.Folders.For + "\\Settings.txt");
comboBox.Text = ini.IniReadValue("Info", "Name");

I am not sure if that is even how it would be done, but I want to list that value in the combo box, for each folder that has that settings.txt.


If I need to clarify anything, please let me know, I can also provide a complete example of my source code if someone needs it zipped up for them. Thank you!


EDIT:

So I see I have gotten quite a few views of this and maybe it is a bit confusing. Here is how I theorize this happening, but needing guidance on making it a reality.

Couldn't I define folders as a string, and do something like
For Each (Folder) //(meaning it will do this block of code for each item in the string, being the folders in the specified directory)
{
IniFile ini = new IniFile("C:\\Users\\first.last\\Desktop\\Projects\\Test Files\\Folders\\" + Folder + "\\Settings.txt");
comboBox.Text = ini.IniReadValue("Info", "Name");
}

Edit #2 - I am going back through my C# tutorials because I remembered something that I learned about the while statement, I thought I could apply it in this case but am having no luck making "folders" turn into a string to even remotely make this possible. I am referring to www.learnvisualstudio.net video number 2010_02_06.
Here was my theory....

string thisFolder = folders; //I can't make this a string because it is already declared and I can't convert it to a sting implicitly...
while (folders != null)
{
//execute
IniFile ini = new IniFile("C:\\Users\\first.last\\Desktop\\Projects\\Test Files\\Folders\\" + thisFolders + "\\Settings.txt");
if (folders = null)
{
comboBox.Text = ini.IniReadValue("Info", "Name");
}
}

In my head this sounded as if it would have worked. But this just isn't the way things work lol...

modified 10-Mar-13 7:23am.

AnswerRe: Searching for a file in multiple directories? Pin
OriginalGriff9-Mar-13 22:39
mveOriginalGriff9-Mar-13 22:39 
GeneralRe: Searching for a file in multiple directories? Pin
Goaty651099-Mar-13 23:05
Goaty651099-Mar-13 23:05 
GeneralRe: Searching for a file in multiple directories? Pin
OriginalGriff9-Mar-13 23:23
mveOriginalGriff9-Mar-13 23:23 
GeneralRe: Searching for a file in multiple directories? Pin
Goaty651099-Mar-13 23:31
Goaty651099-Mar-13 23:31 
GeneralRe: Searching for a file in multiple directories? Pin
OriginalGriff9-Mar-13 23:42
mveOriginalGriff9-Mar-13 23:42 
GeneralRe: Searching for a file in multiple directories? Pin
Goaty651099-Mar-13 23:54
Goaty651099-Mar-13 23:54 
GeneralRe: Searching for a file in multiple directories? Pin
OriginalGriff10-Mar-13 0:00
mveOriginalGriff10-Mar-13 0:00 
GeneralRe: Searching for a file in multiple directories? Pin
Goaty6510910-Mar-13 0:34
Goaty6510910-Mar-13 0:34 
GeneralRe: Searching for a file in multiple directories? Pin
OriginalGriff10-Mar-13 0:55
mveOriginalGriff10-Mar-13 0:55 
GeneralRe: Searching for a file in multiple directories? Pin
Goaty6510910-Mar-13 1:03
Goaty6510910-Mar-13 1:03 
GeneralRe: Searching for a file in multiple directories? Pin
OriginalGriff10-Mar-13 1:12
mveOriginalGriff10-Mar-13 1:12 
GeneralRe: Searching for a file in multiple directories? Pin
Goaty6510910-Mar-13 1:16
Goaty6510910-Mar-13 1:16 
GeneralRe: Searching for a file in multiple directories? Pin
OriginalGriff10-Mar-13 1:23
mveOriginalGriff10-Mar-13 1:23 
QuestionSuggestions: textbox background and foreground colours. Pin
Septimus Hedgehog9-Mar-13 10:58
Septimus Hedgehog9-Mar-13 10:58 
AnswerRe: Suggestions: textbox background and foreground colours. Pin
Ravi Bhavnani9-Mar-13 13:01
professionalRavi Bhavnani9-Mar-13 13:01 
GeneralRe: Suggestions: textbox background and foreground colours. Pin
Septimus Hedgehog9-Mar-13 23:02
Septimus Hedgehog9-Mar-13 23:02 
QuestionIf statement Pin
Sottyoru9-Mar-13 7:07
Sottyoru9-Mar-13 7:07 

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.