
RecursiveDirectoryIterator::getSubPathname 메서드는 디렉토리 전체 이름을 반환합니다. 서브 디렉토리 이름만 반환하고 싶다면, RecursiveIteratorIterator의 getChildren() 메서드를 사용하여 서브 디렉토리만 반복하고, 그 서브 디렉토리에서 getSubPathname 메서드를 사용하면 됩니다.
#hostingforum.kr
php
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/path/to/directory'), RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $file) {
if ($file->isDir()) {
echo $file->getSubPathname() . "n";
}
}
위 코드는 디렉토리 내의 서브 디렉토리 이름만 출력합니다.
또는, RecursiveIteratorIterator의 getChildren() 메서드를 사용하여 서브 디렉토리만 반복하고, 그 서브 디렉토리에서 getSubPathname 메서드를 사용하는 방법도 있습니다.
#hostingforum.kr
php
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/path/to/directory'));
foreach ($iterator->getChildren() as $file) {
echo $file->getSubPathname() . "n";
}
위 코드는 디렉토리 내의 서브 디렉토리 이름만 출력합니다.
이러한 방법으로 디렉토리 내의 서브 디렉토리 이름을 얻을 수 있습니다.
2025-05-23 23:02