I
Ioannis Vranos
The following code is supposed to print all folder names of a folder but it does not work.
Why?
Change the folder in main() to a folder suitable for your system so as to test it.
I created this proof-of-concept example, because I encountered similar recursion problems
in a more complex project.
#using <mscorlib.dll>
// Displays the full names of all contained folders and subfolders *recursively*
void DisplayFolderNames(System::String *folderName)
{
using namespace System;
using namespace System::IO;
DirectoryInfo * const dir= __gc new DirectoryInfo(folderName);
if(!dir->Exists)
return;
// Print contained folder names
DirectoryInfo *dirDirects[]= dir->GetDirectories();
if(dirDirects->Count== 0)
return;
for(long i=0; i<dirDirects->Count; ++i)
{
Console::WriteLine("{0}", dirDirects->FullName);
DisplayFolderNames(dirDirects->FullName);
}
}
int main()
{
DisplayFolderNames(S"D:\\extract\\temp");
}
Why?
Change the folder in main() to a folder suitable for your system so as to test it.
I created this proof-of-concept example, because I encountered similar recursion problems
in a more complex project.
#using <mscorlib.dll>
// Displays the full names of all contained folders and subfolders *recursively*
void DisplayFolderNames(System::String *folderName)
{
using namespace System;
using namespace System::IO;
DirectoryInfo * const dir= __gc new DirectoryInfo(folderName);
if(!dir->Exists)
return;
// Print contained folder names
DirectoryInfo *dirDirects[]= dir->GetDirectories();
if(dirDirects->Count== 0)
return;
for(long i=0; i<dirDirects->Count; ++i)
{
Console::WriteLine("{0}", dirDirects->FullName);
DisplayFolderNames(dirDirects->FullName);
}
}
int main()
{
DisplayFolderNames(S"D:\\extract\\temp");
}