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 & 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 & folders regardless the level of depth... This is what I did ... There are some exceptions!
#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<=MaxPath) {
array <String^> ^fileEntries = Directory::GetFiles(SourceDir);
for each (String^ fileName in fileEntries) {
Console::WriteLine(fileName);
}
}
array<String^> ^SubDirEntries = Directory::GetDirectories(SourceDir);
for each (String^ subdir in SubDirEntries)
if ((File::GetAttributes(subdir) & FileAttributes::ReparsePoint)!= FileAttributes::ReparsePoint)
ScanMyDir(subdir,RecursiveLevel+1);
}
};
int main(array<System::String ^> ^args) {
Scan::ScanMyDir("c://",1);
Console::Read();
return 0;
}
After some modifications (still with some errors):
using namespace System;
using namespace System::IO;
static void ScanMyDir( String^ SourceDir) {
array <String^> ^fileEntries = Directory::GetFiles(SourceDir);
for each (String^ fileName in fileEntries) {
Console::WriteLine(fileName);
}
array<String^> ^SubDirEntries = Directory::GetDirectories(SourceDir);
for each (String^ subdir in SubDirEntries)
if ((File::GetAttributes(subdir) & FileAttributes::ReparsePoint)!= FileAttributes::ReparsePoint)
ScanMyDir(subdir);
}
int main(array<System::String ^> ^args) {
try {
ScanMyDir("C://Windows");
}
catch {
Console::WriteLine("Some Denied files or Folders");
}
return 0;
}
These are the errors:
Error 1 error C2059: syntax error : '{' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 31
Error 6 error C2059: syntax error : '}' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 37
Error 8 error C2059: syntax error : '}' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 37
Error 5 error C2059: syntax error : 'return' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 36
Error 4 error C2061: syntax error : identifier 'WriteLine' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 32
Error 7 error C2143: syntax error : missing ';' before '}' c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 37
Error 2 error C2309: catch handler expected a parenthesized exception declaration c:\Users\Ahmed\documents\visual studio 2010\Projects\eeee\eeee\eeee.cpp 31
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