Hi, I have a main directory like :
/import/
and in /import/ i have lots of sub directories, containing audio files.
I would like to create a php script to move all the audio files from the sub directories into the main directory.
Thanks guys :)
Hi, I have a main directory like :
/import/
and in /import/ i have lots of sub directories, containing audio files.
I would like to create a php script to move all the audio files from the sub directories into the main directory.
Thanks guys :)
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator("/import/"));
$it->rewind();
while($it->valid()) {
$full_path = $it->key();
$relative_path = $it->getSubPath();
if ($it->getDepth() > 0 && preg_match("/regex/", $relative_path)) [
//move stuff
}
$it->next();
}
See RecursiveIteratorIterator and RecursiveDirectoryIterator. You could also encapsulate the iterator in a RegexIterator.
Have a look at opendir(), is_dir()
, copy()
and unlink()
.
What you need to do is:
Open the /import directory and iterate through the listing.
For each entry, if it's a directory (and not . or ..), get the listing of that sub directory.
Then for each audio file in that sub directory, copy to /import/, then use unlink to delete.