{"id":315,"date":"2017-02-11T23:33:45","date_gmt":"2017-02-11T22:33:45","guid":{"rendered":"http:\/\/lab.fawno.com\/?p=315"},"modified":"2022-03-07T15:53:10","modified_gmt":"2022-03-07T14:53:10","slug":"","status":"publish","type":"post","link":"https:\/\/lab.fawno.com\/en\/2017\/02\/11\/mover-un-directorio\/","title":{"rendered":"","raw":""},"content":{"rendered":"","protected":false,"raw":""},"excerpt":{"rendered":"","protected":false,"raw":""},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_editorskit_title_hidden":false,"_editorskit_reading_time":1,"_editorskit_typography_data":[],"_editorskit_blocks_typography":"","_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_es_post_content":"\n

Para una tonter\u00eda que estaba haciendo he necesitado renombrar (aka mover) un directorio de una ruta a otra. Como no existe la funci\u00f3n rename<\/a><\/em> orientada a directorios, he tenido que crearla:<\/p>\n\n\n\n

function path_rename ($from, $to) {\n  if (is_dir($from)) {\n    path_check($to, 0777);\n    $exclude = ['', '.', '..'];\n    foreach (array_diff(scandir($from), $exclude) as $file) {\n      if (is_file($from . DIRECTORY_SEPARATOR . $file)) {\n        rename($from . DIRECTORY_SEPARATOR . $file, $to . DIRECTORY_SEPARATOR . $file);\n      } else {\n        path_rename($from . DIRECTORY_SEPARATOR . $file, $to . DIRECTORY_SEPARATOR . $file);\n      }\n    }\n    rmdir($from);\n  }\n}<\/pre>\n\n\n\n

No hay mucho que decir, salvo que no hace comprobaciones muy exhaustivas y hay que tener cierto cuidado al utilizarla.<\/p>\n\n\n\n

ATENCI\u00d3N<\/strong>: Utiliza la funci\u00f3n path_check<\/em> que he descrito anteriormente<\/a>.<\/p>\n","_es_post_name":"mover-un-directorio","_es_post_excerpt":"","_es_post_title":"Mover un directorio","_en_post_content":"","_en_post_name":"","_en_post_excerpt":"","_en_post_title":"","edit_language":"en","footnotes":""},"categories":[5,3],"tags":[6],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-php","category-tips","tag-php"],"ninja_gutenberg_blocks_featured_media_urls":{"thumbnail":"","ninja_gutenberg_blocks_landscape_large":"","ninja_gutenberg_blocks_portrait_large":"","ninja_gutenberg_blocks_square_large":"","ninja_gutenberg_blocks_landscape":"","ninja_gutenberg_blocks_portrait":"","ninja_gutenberg_blocks_square":"","full":""},"_links":{"self":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/comments?post=315"}],"version-history":[{"count":10,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":1837,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/315\/revisions\/1837"}],"wp:attachment":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/media?parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/categories?post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/tags?post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}