フォルダー内のすべてのファイルをループして削除するプログラムを作成しています。私はそうするために使用NSDirectoryEnumerator
しています。問題は、コードが 1 回だけループし、1 つのファイルを処理してから存在することです。私はこれを NSLog ステートメントから知っています。単一のファイルと、単一のファイルを含むフォルダーで機能します。
関連するコードは次のとおりです。
NSString *fileToNuke = filePath;
NSLog(@"Incinerating %@", fileToNuke);
[spinner startAnimation:self];
#ifdef DEBUG
NSLog(@"Incinerating %i times.", timesToIncinerate);
#endif
if ([fileManager fileExistsAtPath:filePath isDirectory:NULL] && isDir) {
NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:filePath];
//NSString *file;
//file = [directoryEnumerator nextObject];
for (NSString *file in directoryEnumerator) {
// Construct the path of the file to incinerate.
NSString *finalPath = [NSString stringWithFormat:@"%@/%@", filePath, file];
#ifdef DEBUG
NSLog(@"%@", finalPath);
#endif
if (!incinerate(timesToIncinerate, [finalPath cStringUsingEncoding:(NSASCIIStringEncoding)], (int)eraseFile, useNonBlockingRandom, incinerateCallback)) {
[spinner stopAnimation:self];
erasing = NO;
break;
}
[spinner stopAnimation:self];
erasing = NO;
//file = [directoryEnumerator nextObject];
}
} else if (!isDir) {
if (!incinerate(timesToIncinerate, [fileToNuke cStringUsingEncoding:(NSASCIIStringEncoding)], (int)eraseFile, useNonBlockingRandom, incinerateCallback)) {
[spinner stopAnimation:self];
}
[spinner stopAnimation:self];
erasing = NO;
}
// Tell the application waiting on the main thread to finish up with our task by notifing the user of
// our completion.
[self performSelectorOnMainThread:@selector(finishIncineration) withObject:nil waitUntilDone:YES];
while
ループの設定方法と関係があると思われますが、提案を歓迎します。愚かなことをしていることだけはわかっています...