MoFish Posted April 14, 2014 Share Posted April 14, 2014 Hi, I'm using the following code to delete all directories in the root of my website which works well... however.. I'm wanting to amend the code so it does not delete a folder called "install" and also does not delete a file called "configuration.php" Could anyone please advise me on how i could exclude a folder and file? Thanks, MoFish function deleteDirectory($dirPath) { if (is_dir($dirPath)) { $objects = scandir($dirPath); foreach ($objects as $object) { if ($object != "." && $object !="..") { if (filetype($dirPath . DIRECTORY_SEPARATOR . $object) == "dir") { deleteDirectory($dirPath . DIRECTORY_SEPARATOR . $object); } else { unlink($dirPath . DIRECTORY_SEPARATOR . $object); } } } reset($objects); rmdir($dirPath); return true; } } Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 14, 2014 Share Posted April 14, 2014 set permissions to thous files/directories, this is the best method. Quote Link to comment Share on other sites More sharing options...
MoFish Posted April 14, 2014 Author Share Posted April 14, 2014 Which permission level stops the deletion? set permissions to thous files/directories, this is the best method. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 14, 2014 Share Posted April 14, 2014 Which OS is the server running? I guess,it is a linux distro. Quote Link to comment Share on other sites More sharing options...
MECU Posted April 15, 2014 Share Posted April 15, 2014 chmod 000 <filename|directory> you can change the ownership too: chown bad:user <filename|directory> Quote Link to comment Share on other sites More sharing options...
MoFish Posted April 15, 2014 Author Share Posted April 15, 2014 (edited) Hi, @Jazzman - Yes, its using Linux. The folder needs to be writeable via code, but running the deleteDirectory() function should NOT remove the /install folder or file configuration.php. I thought there would of been a simple way to exclude a folder name / file name in the function itself - but am happy to go down the permission route if its better. I'm just not sure what to set it too. @MECU - will chmod 000 allow me to still read/write to the folder? Edited April 15, 2014 by MoFish Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 15, 2014 Share Posted April 15, 2014 The folder needs to be writeable via code, but running the deleteDirectory() function should NOT remove the /install folder or file configuration.php. Then you will need to add/create a new user who will belong to the root's group. So, for all users belong to root's group you'll need to set special permissions on those directories/files. Don't use a root account to create, modify or delete whatever you want, use this account only in emergency case. What linux distro is that? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.