isDir()) { echo 'Directory: ' . $iterator->getSubPathName() . "\n"; } else { echo 'File: ' . $file->getFilename() . ', Sub Path: ' . $iterator->getSubPathName() . "\n"; } } ?>In this example, we are using the RecursiveDirectoryIterator to iterate over the files and directories in the specified directory. We check whether the current item is a directory or a file. If it is a directory, we simply print the sub path name. If it is a file, we print both the filename and the sub path name. This code example does not depend on any external package library.