{"id":57,"date":"2007-08-01T20:02:00","date_gmt":"2007-08-01T20:02:00","guid":{"rendered":"http:\/\/grummfy.be\/blog\/?p=57"},"modified":"2007-08-01T20:02:00","modified_gmt":"2007-08-01T20:02:00","slug":"creation-de-repertoire-automatique-en-php-via-une-structure-txt","status":"publish","type":"post","link":"https:\/\/grummfy.be\/blog\/57","title":{"rendered":"Cr\u00e9ation de r\u00e9pertoire automatique, en php, via une structure txt"},"content":{"rendered":"<p>Nombres de tutoriaux de programmation pr&eacute;sente la structure des diff&eacute;rents r&eacute;pertoires sous la forme d&rsquo;unt exte de cette forme : \/home \/admin \/index     \/ajouter     \/delete     \/news         \/id \/totor<\/p>\n<p>C&rsquo;est souvent assez embettant de recr&eacute;er chaque r&eacute;pertoire alors qu&rsquo;un simple script suffit &#8230;.<\/p>\n<p>Voici ce script<\/p>\n<pre class=\"code php\"><span style=\"color: #000000; font-weight: bold;\">&lt;?php<\/span> &nbsp; <span style=\"color: #0000ff;\">$tab<\/span> = <span style=\"color: #ff0000;\">'    '<\/span>; &nbsp; <span style=\"color: #0000ff;\">$shema<\/span> = &lt;&lt;&lt;UYJY <span style=\"color: #ff0000\">\/home \/admin \/index     \/ajouter     \/delete     \/news         \/id     \/totor<\/span> UYJY; &nbsp; <span style=\"color: #0000ff;\">$shema<\/span> = <a href=\"http:\/\/www.php.net\/str_replace\"><span style=\"color: #000066;\">str_replace<\/span><\/a><span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;<span style=\"color: #000099; font-weight: bold;\">\r<\/span><span style=\"color: #000099; font-weight: bold;\"> <\/span>&quot;<\/span>, <span style=\"color: #ff0000;\">&quot;<span style=\"color: #000099; font-weight: bold;\"> <\/span>&quot;<\/span>, <span style=\"color: #0000ff;\">$shema<\/span><span style=\"color: #66cc66;\">&#41;<\/span>; <span style=\"color: #0000ff;\">$shemas<\/span> = <a href=\"http:\/\/www.php.net\/explode\"><span style=\"color: #000066;\">explode<\/span><\/a><span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;<span style=\"color: #000099; font-weight: bold;\"> <\/span>&quot;<\/span>, <span style=\"color: #0000ff;\">$shema<\/span><span style=\"color: #66cc66;\">&#41;<\/span>; &nbsp; <span style=\"color: #0000ff;\">$curdir<\/span> = <a href=\"http:\/\/www.php.net\/array\"><span style=\"color: #000066;\">array<\/span><\/a><span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #66cc66;\">&#41;<\/span>; <span style=\"color: #0000ff;\">$curdir<\/span><span style=\"color: #66cc66;\">&#91;<\/span><span style=\"color: #cc66cc;\">0<\/span><span style=\"color: #66cc66;\">&#93;<\/span> = <a href=\"http:\/\/www.php.net\/dirname\"><span style=\"color: #000066;\">dirname<\/span><\/a><span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #000000; font-weight: bold;\">__FILE__<\/span><span style=\"color: #66cc66;\">&#41;<\/span> . <span style=\"color: #ff0000;\">'\/rep'<\/span>; <a href=\"http:\/\/www.php.net\/mkdir\"><span style=\"color: #000066;\">mkdir<\/span><\/a><span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #0000ff;\">$curdir<\/span><span style=\"color: #66cc66;\">&#91;<\/span><span style=\"color: #cc66cc;\">0<\/span><span style=\"color: #66cc66;\">&#93;<\/span>, <span style=\"color: #cc66cc;\">0777<\/span><span style=\"color: #66cc66;\">&#41;<\/span>; <span style=\"color: #0000ff;\">$lastNiv<\/span> = <span style=\"color: #cc66cc;\">0<\/span>; &nbsp; <span style=\"color: #b1b100;\">foreach<\/span> <span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #0000ff;\">$shemas<\/span> <span style=\"color: #b1b100;\">as<\/span> <span style=\"color: #0000ff;\">$line<\/span><span style=\"color: #66cc66;\">&#41;<\/span> <span style=\"color: #66cc66;\">&#123;<\/span> \t<span style=\"color: #808080; font-style: italic;\">\/\/profondeur du rep<\/span> \t<span style=\"color: #0000ff;\">$Niv<\/span> = <a href=\"http:\/\/www.php.net\/substr_count\"><span style=\"color: #000066;\">substr_count<\/span><\/a><span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #0000ff;\">$line<\/span>, <span style=\"color: #0000ff;\">$tab<\/span><span style=\"color: #66cc66;\">&#41;<\/span> + <span style=\"color: #cc66cc;\">1<\/span>; &nbsp; \t<span style=\"color: #808080; font-style: italic;\">\/\/nom rep<\/span> \t<span style=\"color: #0000ff;\">$rep<\/span> = <a href=\"http:\/\/www.php.net\/substr\"><span style=\"color: #000066;\">substr<\/span><\/a><span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #0000ff;\">$line<\/span>, <span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #0000ff;\">$Niv<\/span><span style=\"color: #cc66cc;\">-1<\/span><span style=\"color: #66cc66;\">&#41;<\/span> * <a href=\"http:\/\/www.php.net\/strlen\"><span style=\"color: #000066;\">strlen<\/span><\/a><span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #0000ff;\">$tab<\/span><span style=\"color: #66cc66;\">&#41;<\/span><span style=\"color: #66cc66;\">&#41;<\/span>; &nbsp; \t<span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #0000ff;\">$Niv<\/span> &lt; <span style=\"color: #0000ff;\">$lastNiv<\/span><span style=\"color: #66cc66;\">&#41;<\/span> \t<span style=\"color: #66cc66;\">&#123;<\/span> \t\t<span style=\"color: #808080; font-style: italic;\">\/\/r\u00e9pertoire sup\u00e9rieur<\/span> \t\t<span style=\"color: #808080; font-style: italic;\">\/\/delete des chemin inf\u00e9rieur<\/span> \t\t<span style=\"color: #b1b100;\">for<\/span> <span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #0000ff;\">$i<\/span> = <span style=\"color: #0000ff;\">$Niv<\/span> + <span style=\"color: #cc66cc;\">1<\/span>; <span style=\"color: #0000ff;\">$i<\/span> &lt;= <a href=\"http:\/\/www.php.net\/count\"><span style=\"color: #000066;\">count<\/span><\/a><span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #0000ff;\">$curdir<\/span><span style=\"color: #66cc66;\">&#41;<\/span>; <span style=\"color: #0000ff;\">$i<\/span>++<span style=\"color: #66cc66;\">&#41;<\/span> \t\t<span style=\"color: #66cc66;\">&#123;<\/span> \t\t\t<a href=\"http:\/\/www.php.net\/unset\"><span style=\"color: #000066;\">unset<\/span><\/a><span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #0000ff;\">$curdir<\/span><span style=\"color: #66cc66;\">&#91;<\/span><span style=\"color: #0000ff;\">$i<\/span><span style=\"color: #66cc66;\">&#93;<\/span><span style=\"color: #66cc66;\">&#41;<\/span>; \t\t<span style=\"color: #66cc66;\">&#125;<\/span> \t<span style=\"color: #66cc66;\">&#125;<\/span> &nbsp; \t<span style=\"color: #808080; font-style: italic;\">\/\/save du niveau + chemin<\/span> \t<span style=\"color: #0000ff;\">$lastNiv<\/span> = <span style=\"color: #0000ff;\">$Niv<\/span>; \t<span style=\"color: #0000ff;\">$curdir<\/span><span style=\"color: #66cc66;\">&#91;<\/span> <span style=\"color: #0000ff;\">$Niv<\/span> <span style=\"color: #66cc66;\">&#93;<\/span> = <span style=\"color: #0000ff;\">$curdir<\/span><span style=\"color: #66cc66;\">&#91;<\/span> <span style=\"color: #0000ff;\">$Niv<\/span> - <span style=\"color: #cc66cc;\">1<\/span> <span style=\"color: #66cc66;\">&#93;<\/span> . <span style=\"color: #0000ff;\">$rep<\/span>; &nbsp; \t<span style=\"color: #808080; font-style: italic;\">\/\/cr\u00e9ation rep<\/span> \t<span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #66cc66;\">&#40;<\/span><a href=\"http:\/\/www.php.net\/mkdir\"><span style=\"color: #000066;\">mkdir<\/span><\/a><span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #0000ff;\">$curdir<\/span><span style=\"color: #66cc66;\">&#91;<\/span> <span style=\"color: #0000ff;\">$Niv<\/span> <span style=\"color: #66cc66;\">&#93;<\/span>, <span style=\"color: #cc66cc;\">0777<\/span><span style=\"color: #66cc66;\">&#41;<\/span><span style=\"color: #66cc66;\">&#41;<\/span> \t\t<a href=\"http:\/\/www.php.net\/echo\"><span style=\"color: #000066;\">echo<\/span><\/a> <span style=\"color: #ff0000;\">'R\u00e9pertoire ('<\/span> . <span style=\"color: #0000ff;\">$curdir<\/span><span style=\"color: #66cc66;\">&#91;<\/span> <span style=\"color: #0000ff;\">$Niv<\/span> <span style=\"color: #66cc66;\">&#93;<\/span> . <span style=\"color: #ff0000;\">') cr\u00e9\u00e9!&lt;br \/&gt;'<\/span> . <span style=\"color: #ff0000;\">&quot;<span style=\"color: #000099; font-weight: bold;\"> <\/span>&quot;<\/span>; \t<span style=\"color: #b1b100;\">else<\/span> \t\t<a href=\"http:\/\/www.php.net\/echo\"><span style=\"color: #000066;\">echo<\/span><\/a> <span style=\"color: #ff0000;\">'R\u00e9pertoire ('<\/span> . <span style=\"color: #0000ff;\">$curdir<\/span><span style=\"color: #66cc66;\">&#91;<\/span> <span style=\"color: #0000ff;\">$Niv<\/span> <span style=\"color: #66cc66;\">&#93;<\/span> . <span style=\"color: #ff0000;\">') &lt;strong&gt;n<span style=\"color: #000099; font-weight: bold;\">\\'<\/span>a pas&lt;\/strong&gt; \u00eatre cr\u00e9\u00e9!&lt;br \/&gt;'<\/span> . <span style=\"color: #ff0000;\">&quot;<span style=\"color: #000099; font-weight: bold;\"> <\/span>&quot;<\/span>; <span style=\"color: #66cc66;\">&#125;<\/span><\/pre>\n<ul>\n<li><q>$curdir[0]<\/q> : Le r&eacute;pertoire de base o&ugrave; sont cr&eacute;er les r&eacute;pertoires,<\/li>\n<li><q>$shema<\/q> : Le sch&eacute;ma &agrave; suivre pour cr&eacute;er les r&eacute;pertoires.<\/li>\n<li><q>$tab<\/q> : L&rsquo;espace pour un r&eacute;pertoire (tabulation, 4 espaces, &#8230; (doit-&ecirc;tre r&eacute;gulier!)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Nombres de tutoriaux de programmation pr&eacute;sente la structure des diff&eacute;rents r&eacute;pertoires sous la forme d&rsquo;unt exte de cette forme : \/home \/admin \/index \/ajouter \/delete \/news \/id \/totor C&rsquo;est souvent assez embettant de recr&eacute;er chaque r&eacute;pertoire alors qu&rsquo;un simple script suffit &#8230;. Voici ce script &lt;?php &nbsp; $tab = &lsquo; &lsquo;; &nbsp; $shema = &lt;&lt;&lt;UYJY [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"webmentions_disabled_pings":false,"webmentions_disabled":false,"footnotes":""},"categories":[9],"tags":[110,24,42,28],"class_list":["post-57","post","type-post","status-publish","format-standard","hentry","category-dev","tag-php","tag-programmation","tag-script","tag-trucs-et-astuces"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/grummfy.be\/blog\/wp-json\/wp\/v2\/posts\/57","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/grummfy.be\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/grummfy.be\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/grummfy.be\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/grummfy.be\/blog\/wp-json\/wp\/v2\/comments?post=57"}],"version-history":[{"count":0,"href":"https:\/\/grummfy.be\/blog\/wp-json\/wp\/v2\/posts\/57\/revisions"}],"wp:attachment":[{"href":"https:\/\/grummfy.be\/blog\/wp-json\/wp\/v2\/media?parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/grummfy.be\/blog\/wp-json\/wp\/v2\/categories?post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/grummfy.be\/blog\/wp-json\/wp\/v2\/tags?post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}