2010-06-18 92 views

回答

3
$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(); 
} 

RecursiveIteratorIteratorRecursiveDirectoryIterator。您也可以将迭代器封装在RegexIterator中。

+0

不错的解决方案,你让我发现今天真棒。谢谢。 – 0plus1 2010-06-18 15:02:43

+0

+1使用Spl,-1使用过于复杂。基本上,他需要的只是'foreach($它作为$ path => $ file){//将$ path移动到目标dir} - 不需要regex或getDepth或其他东西。只需使用绝对路径。 – Gordon 2010-06-18 15:06:41

+1

@Gordon那么我的8个声望点在哪里? :p – Artefacto 2010-06-18 15:09:15

1

看一看opendir()is_dir(),copy()unlink()

你需要做的是:

打开/进口目录,并通过上市迭代。

对于每个条目,如果它是一个目录(而不是。或..),请获取该子目录的列表。

然后对于该子目录中的每个音频文件,复制到/ import /,然后使用unlink删除。

相关问题