0

我正在尝试使用 php 做一些事情:我有一个包含 2650 个子文件夹的文件夹......是的,很多。目前,我有 2 个脚本在每个子文件夹上处理一个 xml,但我必须手动进入每个文件夹,将 xml 复制到 www 文件夹,为每个文件夹运行两个脚本(localhost/script1.php 和 localhost/script2.php) ...有没有办法在所有子文件夹上运行这两个脚本?这是文件夹的结构:

C:\wamp\www\Games\Game1\Meta-inf\details.xml
C:\wamp\www\Games\Game2\Meta-inf\details.xml
C:\wamp\www\Games\Game3\Meta-inf\details.xml

我想运行一个脚本,我们称它为 runner.php,它执行以下操作:

http://localhost/runner.php
cd Games
cd Game-1
cd Meta-inf
RUN script1.php
RUN script2.php
cd ..
cd ..
cd Game-2
cd Meta-inf
RUN script1.php
RUN script2.php
.
.
.
cd Game-2650
cd Meta-inf
RUN script1.php
RUN script2.php

EXIT foreach
Exit php

这里的问题是我不知道如何制作一个进入 Gamex/Meta-inf/ 并处理 xml 的新 php 脚本。2 个脚本中的每一个都会创建一个新文件(1 个 excel 和 1 个 txt),这些文件应该在 /Game/Gamex/ 文件夹中创建......应该在每个脚本上修改,对吧?

太感谢了!

4

2 回答 2

1

glob()将读取每个文件夹:

foreach(glob('FULL-PATH-TO/Gamex/Meta-inf/*') as $folder) {

  // process each folder in here...

}

如果您将现有代码包装在glob()函数中的处理文件中,它将执行您需要的操作。

于 2015-07-10T13:36:14.300 回答
1

感谢 petebolduc 和 Tom Hart,我能够弄清楚。我将在这里留下完整的代码(我使用 echo 进行测试......)

太感谢了!!!!!

<?php
foreach(glob("C:\\Users\\Usuario\\Desktop\\Nuevos_Juegos\\SM\\*\\META-INF\\") as $folder)
{
    $xml = simplexml_load_file("$folder\\details.xml");
     $result = $xml->xpath('//name');
     foreach ($result as $node) 
     {
        if ( ($node['lang'] == 'en')  )
        {
            echo "$node" . "<br>";
        }

     } 
}
?>
于 2015-07-10T14:24:00.847 回答