Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

SOLVED - Folder and file delete function


Go to End


3 Posts   1557 Views

Avatar
Johnny9

Community Member, 35 Posts

5 September 2014 at 10:44am

Hi, is where folder and file delete function? I have found Filesystem::removeFolder(), but it didn't remove anything. So maybe you know. Thanks :)

Avatar
Willr

Forum Moderator, 5523 Posts

5 September 2014 at 9:17pm

File::onBeforeDelete(); So you call $file->delete();

Avatar
Johnny9

Community Member, 35 Posts

5 September 2014 at 10:23pm

Edited: 05/09/2014 10:26pm

Thanks for reply :) So final code for multi files and folders delete is:

$FilesAndFolders = File::get()->where("\"OwnerID\" =" .$memberID);
foreach($FilesAndFolders as $FileAndFolder){
	$FileAndFolder->delete();	
}

It will delete files and folders also remove all stored entries in database.

Bye bye :)