我有一个包含大量目录的文件夹。我希望以字符串形式返回其中没有更多目录的每个文件夹的路径
示例目录结构
session_start();
require_once __DIR__ . './db_con_marco.php';
if (!isset($_SESSION['userSession'])) {
$msg ="WARNING";
header("Location: ../index.php?errorMessage=" . $msg);
exit; }
$queryText = "
SELECT *
FROM account
WHERE BINARY username = '" . $_SESSION['userSession'] . "' ";
$query = $dbCon->query($queryText);
$userRow = $query->fetch_array();
$uCod = $_POST['codice_dettagli'];
$uCod = $dbCon->real_escape_string($uCod);
$check_cod = $dbCon->query("SELECT codice FROM eventi WHERE codice = '$uCod'");
$count = $check_cod->num_rows;
if($count == 0 ){
$msg ="Evento non presente nel DB";
header("Location: account_marco.php?errorMessage=" . $msg); }
?>
首选输出
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen">
</head>
我已经完成了以下操作,但这将通过目录结构而不是最低级别的目录逐个返回每个文件夹。
<div class = "titolo_evento_selezionato">
<?php
$queryAlpha = "
SELECT NomeEvento, date_format(DataOra, '%d.%m.%y (%H:%i)')
FROM eventi
WHERE BINARY codice = '" .$_POST['codice_dettagli'] . "' ";
$queryEvento = $dbCon->query($queryAlpha);
$EventoSelezionato = $queryEvento->fetch_array();
echo($EventoSelezionato[0]);
echo
'<h7>
<br>' . $EventoSelezionato[1] .'
</h7>';
?>
</div>
<form class = "seleziona_posto" method = "post"
action = "./acquista_evento_action.php? var = <?= $EventoSelezionato[0]; ?>" >
<p> Seleziona sulla mappa il settore scelto e premi "Acquista" </p>
<input class = "input_settore_css" type = "text" placeholder = "Settore posto" name = "input_settore" required >
<input class = "bottone_settore_css" type = "submit" value = "ACQUISTA" name = "btn_settore">
</form>
</body>
感谢您的帮助
答案 0 :(得分:1)
您可以这样做:
function GetLowestLevelRecursive([System.Collections.IList] $directories)
{
$lowestleveldirs = @()
foreach ($dir in $directories)
{
$childDirs = $dir.GetDirectories();
if ($childDirs.Length -gt 0)
{
$lowestleveldirs += GetLowestLevelRecursive $childDirs
}
else
{
$lowestleveldirs += $dir
}
}
return $lowestleveldirs
}
#input directories
$allDirectories = @()
# search for lowest level directories
$lowestlvldirs = GetLowestLevelRecursive $allDirectories
foreach ($dir in $lowestlvldirs)
{
Write-Host $dir.FullName
}
预期输出:
C:\Users\Test\Desktop\xml\xml\User1\User1\user1\Windows\abc
C:\Users\Test\Desktop\xml\xml\User2\User2\user2\Windows1\abc