我正在尝试使用php做一些事情:我有一个包含2650个子文件夹的文件夹……是啊,有那么多。目前,我有2个脚本处理每个子文件夹上的xml,但我必须手动进入每个文件夹,将xml复制到wwwfolder,为每个文件夹运行这两个脚本(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这里的问题是,我不知道如何创建一个新的php脚本,该脚本进入Gamex/Meta-inf/并处理xml。这两个脚本中的每个脚本都会创建一个新文件(1excel和1txt),这些文件应该在/Game/Gamex/文件夹中创建...这应该在每个脚本上修改,对吗?
非常感谢!
发布于 2015-07-10 21:36:14
glob()将读取每个文件夹:
foreach(glob('FULL-PATH-TO/Gamex/Meta-inf/*') as $folder) {
// process each folder in here...
}如果您将处理文件中的现有代码包装在glob()函数中,它将执行您需要的操作。
发布于 2015-07-10 22:24:01
多亏了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>";
}
}
}
?>https://stackoverflow.com/questions/31341846
复制相似问题