ERLEDIGT
NEIN
NEIN
ANTWORTEN
1
1
ZUGRIFFE
409
409
EMPFEHLEN
-
Hallo!
Ich hab ein kleines Skript geschrieben, dass einen Ordner auslesen soll und den Inhalt ausgeben mit Unterscheidung zwischen Ordnern und Dateien. (in weiterer Folge soll es alle Dateien und Unterordner mittels Rekursion kopieren)
in meinem Verseichnis (start) habe ich folgende Dateien/Ordner:
Datei: 1.txt
Datei: 2.txt
Datei: 3.txt
Datei: 4.txt
Ordner: unter_ordner
Jetzt zu meinem Skript:
wenn ich jetzt aber die if-Anweisungen weglasse, dann zeigt er den Inhalt an:PHP-Code:
<?php
function mycopy($source_dir, $dest){
$opendir=opendir($source_dir);
while($content = readdir($opendir)){
if(is_file($content) && $content!="." && $content!="..")
echo "File: ".$content."<br>";
if(is_dir($content) && $content!="." && $content!="..")
echo "Ordner: ".$content."<br>";
}
}
mycopy("start", "ziel");
?>
Ausgabe:PHP-Code:<?php
function mycopy($source_dir, $dest){
$opendir=opendir($source_dir);
while($content = readdir($opendir)){
#if(is_file($content) && $content!="." && $content!="..")
echo "Inhalt: ".$content."<br>";
#if(is_dir($content) && $content!="." && $content!="..")
# echo "Ordner: ".$content."<br>";
}
}
mycopy("start", "ziel");
?>
Inhalt: .
Inhalt: ..
Inhalt: 1.txt
Inhalt: 2.txt
Inhalt: 3.txt
Inhalt: 4.txt
Inhalt: unter_start
Wenn ich beide if-Anweisungen verneine, kommt folgende Ausgabe:
PHP-Code:<?php
function mycopy($source_dir, $dest){
$opendir=opendir($source_dir);
while($content = readdir($opendir)){
if(!is_file($content) && $content!="." && $content!="..")
echo "File: ".$content."<br>";
if(!is_dir($content) && $content!="." && $content!="..")
echo "Ordner: ".$content."<br>";
}
}
mycopy("start", "ziel");
?>
Ausgabe:
File: 1.txt
Ordner: 1.txt
File: 2.txt
Ordner: 2.txt
File: 3.txt
Ordner: 3.txt
File: 4.txt
Ordner: 4.txt
File: unter_start
Ordner: unter_start
Hab leider keinen Fehler gefunden!
-
Falls sich das Skript nicht im selben Verzeichnis befindet wie $source_dir, müsstest du vor $content noch den Pfad zu $source_dir setzen...sonst kann das Skript nix finden.
Ähnliche Themen
-
is_file() funktioniert nicht korrekt bei Überordnern!
Von Galotti im Forum PHPAntworten: 2Letzter Beitrag: 01.01.05, 20:02 -
is_dir() & is_file() arbeiten nicht so wie sie soll'n
Von Surma im Forum PHPAntworten: 2Letzter Beitrag: 17.10.04, 19:51 -
is_dir geht nicht
Von low-group im Forum PHPAntworten: 6Letzter Beitrag: 16.08.04, 19:07 -
is_dir, is_file: mal gehts, mal nicht :-(
Von faron im Forum PHPAntworten: 2Letzter Beitrag: 12.08.03, 13:53 -
is_dir() und filesize() funktionieren unter win aber nicht unter linux
Von Bomber im Forum PHPAntworten: 0Letzter Beitrag: 30.05.02, 23:07





Zitieren
Login






[PHP][Snippet] Array zu XML konvertieren