Page 1 of 1

Delete folder while running update

Posted: Thu Jul 24, 2025 2:24 pm
by musicscore
Hey ther again.

I'm almost finished versie 0.3 of my module and are change the methode.upgrade.php.
With this php file I want to delete a complete folder (including the files in that folder).
Seaching the internet I found this code :

Code: Select all

	// delete jquery directory
		$dir = "/modules/IwPopupManager/jquery";
		if (!empty($dir)) { 
			array_map('unlink', array_filter((array) array_merge(glob("$dir/*"))));
		}
		rmdir($dir);
So I modified the methode.upgrade.php file and tested the upgrade :
  • Installed versie 0.1
  • Copied versie 0.3 using ftp
  • Did the upgrade in the cmsms console
Everything worked except the deletion of the folder.

Please advise how to delete the folder while upgrading the module.

T.I.A. again.

Re: Delete folder while running update

Posted: Fri Jul 25, 2025 10:02 am
by musicscore
I checked the Gallery module (methode.upgrade.php) and found @unlink command.
Put this code in my methode.upgrade.php without any luck :

Code: Select all

@unlink("/modules/IwPopupManager/jquery/popup.js");
@rmdir('/modules/IwPopupManager/jquery');
Please advise. If this is solved I can upload the new version of my module (version 0.3)

T.I.A.

Re: Delete folder while running update

Posted: Mon Jul 28, 2025 3:19 pm
by chrisbt
This is the code I used in the ECB2 module to remove files & dirs on upgrade:

Code: Select all

$module_path = $this->GetModulePath();
if ( version_compare($oldversion, '1.8') < 0 ) {
    // remove sub dirs
    $dirsToRemove = ['/lib/js/images', '/icons'];
    foreach ($dirsToRemove as $delDir) {
        foreach (glob($module_path.$delDir.'/*.*') as $filename) @unlink($filename);
        @rmdir($module_path.$delDir);
    }
    // individual files to remove
    $filesToRemove = ['/lib/js/mColorPicker.min.js', '/changelog.inc', '/lib/js/jquery-ui-timepicker-addon.js', 
        '/lib/js/colpick.js'];
    foreach ($filesToRemove as $delFile) @unlink($module_path.$delFile);
}
It looks like your issue is that you are not using the full module path.

[Solved] Delete folder while running update

Posted: Mon Jul 28, 2025 5:17 pm
by musicscore
Thanks a lot Chris.
That did the job.