raivis Posted November 29, 2004 Report Share Posted November 29, 2004 Izdzēst direktoriju ar tajā esošiem failiem un direktorijām, neuzskaitot katru failu un direktoriju atsevišķi!? unlink("data/users/g/gallery/title.txt"); rmdir("data/users/g/gallery/"); unlink("data/users/g/inbox.txt"); unlink("data/users/g/outbox.txt"); unlink("data/users/g/info.txt"); rmdir("data/users/g/"); pieņemsim dzēšamā direktorija ir $trash ar rmdir($trash); nav līdzēts, ja tajā atrodas faili un direktorijas.. Vai vispār tas ir iespējams? Link to comment Share on other sites More sharing options...
bubu Posted November 30, 2004 Report Share Posted November 30, 2004 (edited) var. primitīva rekursija: function DeleteDir($dir) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { if (is_dir($file)) { DeleteDir($dir . '/' . $file); rmdir($dir) . '/' . $file); } else { unlink($dir); } } closedir($dh); } } DeleteDir($trash); // atceries, ka jābūt tiesībām to visu dzēst!!!! Edited November 30, 2004 by bubu Link to comment Share on other sites More sharing options...
Venom Posted November 30, 2004 Report Share Posted November 30, 2004 iespējams, ja vari palaist ar exec vai tml. rekursīvo delete komandu attiecīgai OS, citādi še tev pseidokodu function recdel($topdir) { $dh=opendir($topdir); while (($item=readdir($dh)) !== false) switch ($item) { case '.': case '..': break; default: @chmod($topdir.$item,0777);//jic if (is_dir($topdir.$item)) recdel($topdir.$item.'/'); else unlink($topdir.$item); }//sw rmdir($topdir); } recdel('/var/www/home/public_html/tmp/'); //attīrāmā un dzēšamā direktorija Link to comment Share on other sites More sharing options...
raivis Posted November 30, 2004 Author Report Share Posted November 30, 2004 Skripts nenostrādā!? function DeleteDir($dir) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { if (is_dir($file)) { DeleteDir($dir . '/' . $file); rmdir($dir . '/' . $file); } else { unlink($dir); } } closedir($dh); } } $trash = "del01/"; DeleteDir($trash); // atceries, ka jābūt tiesībām to visu dzēst!!!! } Bet šis skripts izdzēš tikai norādītās direktorijas saturu, bet dzēšot direktorijas, izmet error: function recdel($topdir) { $dh=opendir($topdir); while (($item=readdir($dh)) !== false) switch ($item) { case '.': case '..': break; default: @chmod($topdir.$item,0777);//jic if (is_dir($topdir.$item)) recdel($topdir.$item.'/'); else unlink($topdir.$item); }//sw rmdir($topdir); } recdel('del01/'); //attīrāmā un dzēšamā direktorija Warning: rmdir(del01/13/) [function.rmdir]: Permission denied in c:\wamp\www\projects\delete.php on line 18 Warning: rmdir(del01/fa/) [function.rmdir]: Permission denied in c:\wamp\www\projects\delete.php on line 18 Warning: rmdir(del01/) [function.rmdir]: Permission denied in c:\wamp\www\projects\delete.php on line 18 line 18= rmdir($topdir); rmdir('del01/fa/'); //Bet šādejādi tiek izdzēsta direktorija ..tā ka apgalvojums Permission denied nav patiess. Link to comment Share on other sites More sharing options...
Analgiins Posted November 30, 2004 Report Share Posted November 30, 2004 kraasotaajs Raivis :) Kaa tev pacietiiba te kraasoties, pat jautaajuma ziimei lielaaks fonts Ja Permission denied nu taatad nav tiesiibu dzeest, Venom savaa skriptaa jau pirms dzeeshanas pieshkjir maksimaalaas tiesiibas: @chmod($topdir.$item,0777);//jic Link to comment Share on other sites More sharing options...
Venom Posted November 30, 2004 Report Share Posted November 30, 2004 jic == Just In Case ;) nu mazliet piedomā Warning: rmdir(del01/fa/) [function.rmdir]: Permission denied in c:\wamp\www\projects\delete.php on line 18 un rmdir('del01/fa/'); //Bet šādejādi tiek izdzēsta direktorija kaut kā neštimmējas kopā Link to comment Share on other sites More sharing options...
raivis Posted November 30, 2004 Author Report Share Posted November 30, 2004 Bet kādēļ, izdzēš tikai direktorijas satura failus, bet ne pašas direktorijas? un izvada: Warning: rmdir(del01/13/) [function.rmdir]: Permission denied in c:\wamp\www\projects\delete.php on line 18 Warning: rmdir(del01/fa/) [function.rmdir]: Permission denied in c:\wamp\www\projects\delete.php on line 18 Warning: rmdir(del01/) [function.rmdir]: Permission denied in c:\wamp\www\projects\delete.php on line 18 function recdel($topdir) { $dh=opendir($topdir); while (($item=readdir($dh)) !== false) switch ($item) { case '.': case '..': break; default: @chmod($topdir.$item,0777);//jic if (is_dir($topdir.$item)) recdel($topdir.$item.'/'); else unlink($topdir.$item); }//sw rmdir($topdir); } recdel('del01/'); //attīrāmā un dzēšamā direktorija Kur kļūda 18 rindā?: rmdir($topdir); Kaut kas neštimē!.. Link to comment Share on other sites More sharing options...
raivis Posted November 30, 2004 Author Report Share Posted November 30, 2004 Šādejādi nav viss risināts!: rmdir("'".$topdir."'"); Warning: rmdir('del01/13/') [function.rmdir]: No such file or directory in c:\wamp\www\projects\delete.php on line 18 Warning: rmdir('del01/fa/') [function.rmdir]: No such file or directory in c:\wamp\www\projects\delete.php on line 18 Warning: rmdir('del01/') [function.rmdir]: No such file or directory in c:\wamp\www\projects\delete.php on line 18 Link to comment Share on other sites More sharing options...
kirils Posted December 1, 2004 Report Share Posted December 1, 2004 jaa, maxlinieks gan Tu esi. psc, buutu man te valdiishana kraasas, smailiji un citas fignjas sen buutu atsleegtas. iipashi taadiem kaa Tu. vai visus skriptus izpildi no viena skatpunkta? tb mosh Tu venom skriptu laid ejot uz www.blablabla.lv/test.php bet savu rmdir testee no lokaali palaizhot `php /www/webroot/test.php` ? anyway, iemeegjini sho f-ju: function recdel($dir){ $dir=escapeshellargs($dir); exec ("rm -r -- ./$dir"); // ./ tiek pielikts JIC ;> ja nu sagribas / dzeest. } Link to comment Share on other sites More sharing options...
bubu Posted December 1, 2004 Report Share Posted December 1, 2004 function DeleteDir($dir) { ... } $trash = "del01/"; ... vajag $trash = "del01"; bez / Link to comment Share on other sites More sharing options...
Venom Posted December 1, 2004 Report Share Posted December 1, 2004 nu ta manējā rmdir(rtrim($topdir,'/')); citādi mūsu māxlinieks neiedomāsies Link to comment Share on other sites More sharing options...
raivis Posted December 1, 2004 Author Report Share Posted December 1, 2004 Kur kļūda!? ..piedodiet!- es kļūdu nesaskatu, bet tad kādēļ Warning.. nu ta manējā rmdir(rtrim($topdir,'/')); citādi mūsu māxlinieks neiedomāsies <?phpfunction recdel($topdir) { $dh=opendir($topdir); exec("rm -r -- ./$topdir"); while (($item=readdir($dh)) !== false) switch ($item) { case '.': case '..': break; default: @chmod($topdir.$item,0777);//jic if (is_dir($topdir.$item)) { recdel($topdir.$item.'/'); } else { unlink($topdir.$item); } }//sw #$topdir=escapeshellarg($topdir); //Warning: rmdir("del01/13/") [function.rmdir]: Invalid argument in c:\wamp\www\projects\delete.php on line 21 rmdir(rtrim($topdir)); } recdel('del01/'); //attīrāmā un dzēšamā direktorija.. ?> izmet ārā: Warning: rmdir(del01/13/) [function.rmdir]: Permission denied in c:\wamp\www\projects\delete.php on line 21 Warning: rmdir(del01/fa/) [function.rmdir]: Permission denied in c:\wamp\www\projects\delete.php on line 21 Warning: rmdir(del01/) [function.rmdir]: Permission denied in c:\wamp\www\projects\delete.php on line 21 Link to comment Share on other sites More sharing options...
bubu Posted December 1, 2004 Report Share Posted December 1, 2004 Tev nav tiesību dzēst failus. Tur tā rakstīts skaidrā angļu valodā. Link to comment Share on other sites More sharing options...
raivis Posted December 1, 2004 Author Report Share Posted December 1, 2004 Tev nav tiesību dzēst failus. Tur tā rakstīts skaidrā angļu valodā. Bet kādēļ nav nakā līdzēts ar @chmod($topdir.$item,0777); ? Link to comment Share on other sites More sharing options...
raivis Posted December 1, 2004 Author Report Share Posted December 1, 2004 Paldies par to pašu! -- Šāds skripts strādā: function deldir($dir) { $dh=opendir($dir); while ($file=readdir($dh)) { if($file!="." && $file!="..") { $fullpath=$dir."/".$file; if(!is_dir($fullpath)) { unlink($fullpath); } else { deldir($fullpath); } } } closedir($dh); if(rmdir($dir)) { return true; } else { return false; } } deldir("del01/"); Link to comment Share on other sites More sharing options...
Recommended Posts