Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Finally I completed the short project.To get the list of files and sub directories, I made use of <code>.NET Framework namespace "System"</code>.It has got classes like "<code>FileInfo</code>" and "<code>DirectoryInfo</code>"(both belong to <code>System::IO</code>) which do the above required task.But here,all the string related stuff is of <code>System::String</code> , not of <code>std::string</code>.To convert <code>System::String</code> to <code>std::string</code>, I used the following code(I got this conversion's code from a forum and it worked fine without any error):</p> <pre><code>string Str2str(String ^a) { array&lt;Byte&gt; ^chars = System::Text::Encoding::ASCII-&gt;GetBytes(a); pin_ptr&lt;Byte&gt; charsPointer = &amp;(chars[0]); char *nativeCharsPointer = reinterpret_cast&lt;char *&gt;(static_cast&lt;unsigned char *&gt;(charsPointer)); string native(nativeCharsPointer, chars-&gt;Length); return native; } </code></pre> <p>Here is a short code for getting list of sub directories from a drive(D: drive is going to be searched):</p> <pre><code> #include&lt;iostream&gt; #using&lt;mscorlib.dll&gt; using namespace strd; using namespace System; using namespace System::IO; int main() {int count=50; string name[count];//to hold directories names string b; int s=0; DirectoryInfo^ di = gcnew DirectoryInfo("d:\\"); if(di-&gt;Exists) {array&lt;DirectoryInfo^&gt;^diArr = di-&gt;GetDirectories(); Collections::IEnumerator^ myEnum = diArr-&gt;GetEnumerator(); while ( myEnum-&gt;MoveNext() ) {DirectoryInfo^ dri = safe_cast&lt;DirectoryInfo^&gt;(myEnum-&gt;Current); String ^a=(dri-&gt;Name-&gt;ToString()); int n=b.size(); b=Str2str(a); `// code given in the starting` if (s&lt;count) {name[s]=b; s++;} } </code></pre> <p>This involves Managed C++ knowledge. Visit these:</p> <p><a href="http://msdn.microsoft.com/en-us/library/68td296t.aspx" rel="nofollow">.NET Programming Guide</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/ms379617%28VS.80%29.aspx" rel="nofollow">C++: The Most Powerful Language for .NET Framework Programming</a></p> <p>I compiled this on Visual Studio 2008. I will be very grateful if you appriciate my effort.Further suggestions are most welcomed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload