Hi,
I've got the following code, based on the example at
http://msdn.microsoft.com/en-us/library/07wt70x2.aspx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
void ProcessDirectory( String^ targetDirectory )
{
if (Directory::Exists( targetDirectory )) {
printf("Directory : %s\n", targetDirectory);
// Recurse into subdirectories of this directory.
array<String^>^subdirectoryEntries = Directory::GetDirectories( targetDirectory );
IEnumerator^ dirs = subdirectoryEntries->GetEnumerator();
while ( dirs->MoveNext() )
{
String^ subdirectory = safe_cast<String^>(dirs->Current);
ProcessDirectory( subdirectory );
}
}
}
int main(int argc, char **argv)
{
ProcessDirectory( "C:\\" );
}
|
This should be (I reckoned) a simple recursive iteration through the directories on my hard drive, but it keeps crashing saying that paths are too long.
The reason they seem too long is that when it gets to Application Data, it starts repeating the Application Data directory name. The error is below, any help is very much appreciated, as I am stuck :( :
Directory :
C:\Documents and Settings\All Users\Application Data\Application Dat
a\Application Data\Application Data\Application Data\Application Data\Applicatio
n Data\Application Data\Application Data\Application Data\Adobe\CameraRaw\Camera
Profiles\Camera\Canon EOS 1000D
Unhandled Exception: System.IO.PathTooLongException: The specified path, file na
me, or both are too long. The fully qualified file name must be less than 260 ch
aracters, and the directory name must be less than 248 characters.
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPath
Length)
at System.IO.Path.GetDirectoryName(String path)
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String origina
lUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`
1 resultHandler)