GetFiles

This is a discussion on GetFiles within the C++ Programming forums, part of the General Programming Boards category; I am using Directory::GetFiles Method (Path, SeachPattern) to find .txt files in folders. The code that I am using look ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    383

    GetFiles

    I am using Directory::GetFiles Method (Path, SeachPattern) to find .txt files in folders. The code that I am using look like this (I will put the selected folders *.txt files in the textBox1):


    Code:
    folderBrowserDialog1->ShowDialog();
    System::String ^ files3 = folderBrowserDialog1->SelectedPath; 
    
    this->textBox1->Text = Directory::GetFiles(files3,"*.txt");
    The compiler says that "Directory" is a undeclard identifier and left of .GetFiles must have class/struct/union.

    I am not sure if I can figure out what is missing, I have a feeling that I need a string array in any way ?
    Last edited by Coding; 02-11-2008 at 05:44 PM.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Directory is located inside System::IO. So either use
    System::IO::Directory::GetFiles or put using System::IO;
    in your source file, I believe.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    Yes I tried this too but was not sure if it was needed but I have put this now then and the compiler says:

    cannot convert parameter 1 from 'cli::array<Type,dimension> ^' to 'System::String ^
    with
    [
    Type=System::String ^,
    dimension=1
    ]

    I am not sure what could be ment by this. What is a cli::array etc...
    It seems that files3 get another format when using System::IO as that perheps is using this format and then it needs to be converted
    to System::string ^ that a text1 box can use.
    I will look this up.
    Last edited by Coding; 02-12-2008 at 08:03 AM.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    It's obvious to me that it's an array, just upon reading the word cli::array.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    I cant figure this out. I have googling all examples of this but cant find anything that I can understand.

    I dont really understand the first logic of what is needed to do. All that an array should be needed in any way and this array is called: cli::array. What is the difference with a cli::array and an array.
    Following a msdn example and trying to do something, I have done this:

    Code:
    	folderBrowserDialog1->ShowDialog();
    	System::String ^ files3 = folderBrowserDialog1->SelectedPath; 
    		
    	List<String ^> ^files4 = gcnew List<String ^>;
                    List = System::IO::Directory::GetFiles(files3,"*.txt");
    		
    	this->textBox1->Text = List;
    So the only thing I can think of what I am doing is to create a List Array of String ^ type where I will put all .txt files in. So later when write List = System::IO etc... files3 will be saved in this List with correct file type, string ^ so this later will be put in the textBox1.
    So any point in the right direction would be needed I think.
    Last edited by Coding; 02-12-2008 at 03:46 PM.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Quote Originally Posted by Coding View Post
    I dont really understand the first logic of what is needed to do. All that an array should be needed in any way and this array is called: cli::array. What is the difference with a cli::array and an array.
    My understanding is that an array in C++/CLI is of type cli::array. So cli::array is an array, and there's no such thing as "pure" array as in just a collection of objects. You can see it as similar to std::vector as an array.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    okay. That makes it a bit easier to understand that. I dont know if it is ment to write something like this then. Still when doing this std::vector * cannot convert to System::string ^:
    Anyway I suppose I will fill up what ever will be where List = is now with all the files found in files3. If I can understand that it would be easier to continue solving the function needed.
    Thanks...
    Code:
    std::vector<string> List(100);
    
    List = System::IO::Directory::GetFiles(files3,"*.txt");
    Last edited by Coding; 02-12-2008 at 04:34 PM.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    I never said use std::vector. Managed and native don't mix.
    I suggest you go back to C# or just unmanged C++, because this obviously seem to confuse you to no end.
    Do not mix native and managed.
    Mmkay? Your code above will fail in very possible kind of way.
    And again, I don't know C++/CLI, so I don't know how arrays work there, and I don't know how to solve your problem.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    okay that is no problem, I understand. For the moment I have no time to change to C# because it will meen for me to translate 15 pages with code and solutions and that will take another month or more because I am quite new to this. Anyway I have that in mind for later to mention. Perheps if can come nearer a solution I can post again and see if someone have any idea.
    thanks..

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21