Note that there are some explanatory texts on larger screens.

plurals
  1. POLooping through all system files & folders using C++ CLI
    text
    copied!<p>i have found C# code can loop through any directory we specify, i tried to convert it to C++/CLI and make it looping through all system files &amp; folders. The problem is the code let you to determine the level of depth need to scan! What I need is to make it loops all files &amp; folders regardless the level of depth... This is what I did ... There are some exceptions!</p> <pre><code>#include "stdafx.h" using namespace System; using namespace System::IO; ref class Scan { public: static int MaxPath=260000000; static void ScanMyDir( String^ SourceDir,int RecursiveLevel) { if(RecursiveLevel&lt;=MaxPath) { array &lt;String^&gt; ^fileEntries = Directory::GetFiles(SourceDir); for each (String^ fileName in fileEntries) { Console::WriteLine(fileName); } } array&lt;String^&gt; ^SubDirEntries = Directory::GetDirectories(SourceDir); for each (String^ subdir in SubDirEntries) if ((File::GetAttributes(subdir) &amp; FileAttributes::ReparsePoint)!= FileAttributes::ReparsePoint) ScanMyDir(subdir,RecursiveLevel+1); } }; int main(array&lt;System::String ^&gt; ^args) { Scan::ScanMyDir("c://",1); Console::Read(); return 0; } </code></pre> <hr> <p>After some modifications (still with some errors):</p> <pre><code>using namespace System; using namespace System::IO; static void ScanMyDir( String^ SourceDir) { array &lt;String^&gt; ^fileEntries = Directory::GetFiles(SourceDir); for each (String^ fileName in fileEntries) { Console::WriteLine(fileName); } array&lt;String^&gt; ^SubDirEntries = Directory::GetDirectories(SourceDir); for each (String^ subdir in SubDirEntries) if ((File::GetAttributes(subdir) &amp; FileAttributes::ReparsePoint)!= FileAttributes::ReparsePoint) ScanMyDir(subdir); } int main(array&lt;System::String ^&gt; ^args) { try { ScanMyDir("C://Windows"); } catch { Console::WriteLine("Some Denied files or Folders"); } return 0; } </code></pre> <p>These are the errors:</p> <blockquote> <p>Error 1 error C2059: syntax error : '{' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 31</p> <p>Error 6 error C2059: syntax error : '}' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 37</p> <p>Error 8 error C2059: syntax error : '}' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 37</p> <p>Error 5 error C2059: syntax error : 'return' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 36</p> <p>Error 4 error C2061: syntax error : identifier 'WriteLine' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 32</p> <p>Error 7 error C2143: syntax error : missing ';' before '}' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 37</p> <p>Error 2 error C2309: catch handler expected a parenthesized exception declaration c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 31</p> <p>Error 3 error C2319: 'catch' must be followed by a compound statement. Missing '{' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 32</p> </blockquote>
 

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