קריאת קבצים DIR

  • פותח הנושא dando
  • פורסם בתאריך

dando

New member
קריאת קבצים DIR

אני מנסה לקרוא רקורסיבית מ PATH מסויים את כל הקבצים תחתיו עם ה PATH המלא שלהם. הבעיה היא שכאשר הפונקציה קוראת לעצמה היא לא חוזרת בסוף הקריאה לאותו מקום בו היא קראה לעצמה ... <DIV> <html> <body> <?php $folder_path=´C:/phpdev/www´; file_system($folder_path); function file_system($folder_path) { echo "<BR>".$folder_path."<BR>"; chdir($folder_path); echo "<BR><font color=green> ".$folder_path."</font><BR>"; $handle=opendir($folder_path); while ($file = readdir($handle)) { $files[]=$file; } foreach ($files as $file){ if ($file != "." && $file != "..") { if (!is_dir($file)) { echo "<b> file</b> ".$folder_path.´/´.$file."<BR>"; } } } echo $folder_path; $handle=opendir($folder_path); while ($file = readdir($handle)) { $files[]=$file; } foreach ($files as $file){ if ($file != "." && $file != "..") { if (is_dir($file)) { echo "<font color=blue>Dir $folder_path/$file </font><BR>" ; $temp=$folder_path.´/´.$file; file_system($temp); } } } }; ?> </body> </html> </DIV>
 

dando

New member
מקווה שזה יותר ברור

<DIV> <html> <body> <?php $folder_path=´C:/phpdev/www´; file_system($folder_path); function file_system($folder_path) { echo "<BR>".$folder_path."<BR>"; chdir($folder_path); echo "<BR><font color=green> ".$folder_path."</font><BR>"; $handle=opendir($folder_path); while ($file = readdir($handle)) { $files[]=$file; } foreach ($files as $file){ if ($file != "." && $file != "..") { if (!is_dir($file)) { echo "<b> file</b> ".$folder_path.´/´.$file."<BR>"; } } } echo $folder_path; $handle=opendir($folder_path); while ($file = readdir($handle)) { $files[]=$file; } foreach ($files as $file){ if ($file != "." && $file != "..") { if (is_dir($file)) { echo "<font color=blue>Dir $folder_path/$file </font><BR>" ; $temp=$folder_path.´/´.$file; file_system($temp); } } } }; ?> </body> </html> </DIV>
 

dando

New member
../images/Emo5.gif

<DIV align=left dir=rtl> <html> <body> <?php $folder_path=´C:/phpdev/www´; file_system($folder_path); function file_system($folder_path) { echo "<BR>".$folder_path."<BR>"; chdir($folder_path); echo "<BR><font color=green> ".$folder_path."</font><BR>"; $handle=opendir($folder_path); while ($file = readdir($handle)) { $files[]=$file; } foreach ($files as $file){ if ($file != "." && $file != "..") { if (!is_dir($file)) { echo "<b> file</b> ".$folder_path.´/´.$file."<BR>"; } } } echo $folder_path; $handle=opendir($folder_path); while ($file = readdir($handle)) { $files[]=$file; } foreach ($files as $file){ if ($file != "." && $file != "..") { if (is_dir($file)) { echo "<font color=blue>Dir $folder_path/$file </font><BR>" ; $temp=$folder_path.´/´.$file; file_system($temp); } } } }; ?> </body> </html> </DIV>
 

תמר,

New member
צריך לכתוב div align=left dir=ltr

מצד שני, אם אתה רוצה עזרה עם הקוד - שים הערות. זה לא קל להבין "למה התכוון המשורר".
 

dando

New member
אני חושב

שכוונת המשורר די ברורה :) סה"כ פונקציה שמתחילה מ PATH מסויים בלולאה שבודקת כל קובץ אם הוא קובץ או תיקייה, ואם הוא תקייה אז הפונקציה נקראת שוב... <DIV align=left dir=ltr> <html> <body> <?php $folder_path=´C:/phpdev/www´; file_system($folder_path); function file_system($folder_path) { echo "<BR>".$folder_path."<BR>"; chdir($folder_path); echo "<BR><font color=green> ".$folder_path."</font><BR>"; $handle=opendir($folder_path); while ($file = readdir($handle)) { $files[]=$file; } foreach ($files as $file){ if ($file != "." && $file != "..") { if (!is_dir($file)) { echo "<b> file</b> ".$folder_path.´/´.$file."<BR>"; } } } echo $folder_path; $handle=opendir($folder_path); while ($file = readdir($handle)) { $files[]=$file; } foreach ($files as $file){ if ($file != "." && $file != "..") { if (is_dir($file)) { echo "<font color=blue>Dir $folder_path/$file </font><BR>" ; $temp=$folder_path.´/´.$file; file_system($temp); } } } }; ?> </body> </html> </DIV>
 

תמר,

New member
אתה צריך לעשות chdir לספריה הקודמת

בסיום הפונקציה, אחרת אתה נשאר בספריה האחרונה אליה עשית chdir. (אתה יכול לשים קריאה ל-getcwd בתחילת הפונקציה, כך יהיה לך את המיקום הראשוני) (בעניין היישור - השתמש באותיות קטנות
, ובעניין המשורר: לא הבנתי למה אתה צריך שתי קריאות ל-readdir. אני חושבת שאפשר לקרוא פעם אחת, הרי מדובר בפונקציה רקורסיבית, לא?)
 

תמר,

New member
אפשרות נוספת-לא להשתמש ב-chdir

אלא לשרשר את שם הספריה המקורית לשם הקובץ.
 

dando

New member
האמת ניסיתי בקריאה אחת

וגם לא יצא. זה נוסח של נסיון אחר שבו שיחקתי עם עוד כמה דברים.
 

dando

New member
ב CHDIR אני אמור

להשתמש רק כאשר אני מסיים עם התיקייה האחרונה ... איך אני ידע שאני באחרונה??
 

תמר,

New member
אני מצרפת פונקציה שעבדה אצלי

לא צריך chdir.
function file_system($folder_path) { echo "<BR><font color=green>".$folder_path."</font><BR>"; $handle=opendir($folder_path); while ($file = readdir($handle)) { $files[]=$file; } closedir($handle); foreach($files as $file) { if($file != ".." && $file != "." && !is_dir("$folder_path/$file")) { echo "<b> file</b> ".$folder_path.´/´.$file."<BR>"; } } foreach($files as $file) { if($file != ".." && $file != "." && is_dir("$folder_path/$file")) { file_system("$folder_path/$file"); } } }​
 
למעלה