Recursive Remove Directory |
[eluser]Jay Logan[/eluser]
Had to piece together a helper that will allow me to delete a folder and all its contents (including subfolders). Here is the code I'm using in case anyone else would like use it. recursive_helper.php in custom helpers folders. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Then you $this->load->helper('recursive') and run the remove_directory() function. Hope this helps.
[eluser]drewbee[/eluser]
What was wrong with the file helper delete_files() ?? http://ellislab.com/codeigniter/user-gui...elper.html
[eluser]Jay Logan[/eluser]
I tried it but it only deleted the files, not the actual folders.
[eluser]drewbee[/eluser]
Yeah... you gotta pass TRUE as a second param to it.
[eluser]Jay Logan[/eluser]
But that would only delete the folders and files WITHIN the specified folder. What if I want to delete the specified folder and everything (files and folders) in it? Will it work?
[eluser]drewbee[/eluser]
Code: if ( ! function_exists('delete_files')) A quick look at the code sais yes. It removes all the files then deletes the directory if it is set to true.
[eluser]Jay Logan[/eluser]
Just tried delete_files function with TRUE as second param and it did not remove source directory but it deleted all sub directories and files. Thanks anyway.
[eluser]bcorcoran[/eluser]
Using this knowledge couldn't you create a much simpler helper file utilizing the built in delete_files() function?
[eluser]Jay Logan[/eluser]
I'm sure someone could. I didn't write the above code. Found it on Google and turned it into a CI helper. Works fine for me. What I actually did was add the function into my base_controller.php (which I include in all my other controllers) then I access it by $this->remove_directory(PATH). But I figured most people don't have there CI set up in that way so I turned it into a helper file for others. It seems like such a minor feature and I was surprised to see CI didn't already support it. But PHP doesn't have such a function either so...figures. |
Welcome Guest, Not a member yet? Register Sign In |