delete directory

@param dir
@param forceDelete
@throws PageException
199571
public static void actionDelete(PageContext pc, Resource dir, boolean forceDelete, String serverPassword) throws PageException {
	SecurityManager securityManager = pc.getConfig().getSecurityManager();
	securityManager.checkFileLocation(pc.getConfig(), dir, serverPassword);

	// directory doesn't exist
	if (!dir.exists()) {
	    if (dir.isDirectory()) throw new ApplicationException("directory [" + dir.toString() + "] doesn't exist");
	    else if (dir.isFile()) throw new ApplicationException("file [" + dir.toString() + "] doesn't exist and isn't a directory");
	}

	// check if file
	if (dir.isFile()) throw new ApplicationException("can't delete [" + dir.toString() + "], it isn't a directory it is a file");

	// delete directory
	try {
	    dir.remove(forceDelete);
	}
	catch (IOException e) {
	    throw Caster.toPageException(e);
	}
    }
1207450
private void removeTempJavaFolder() throws IOException {
        if (removeJavaDir) {
            FileUtils.forceDelete(new File(rootDirectory + directoryName + this.javaDirPath));
        } else if (removeMainDir) {
            FileUtils.forceDelete(new File(rootDirectory + directoryName + this.mainDirPath));
        } else if (removeSrcDir) {
            FileUtils.forceDelete(new File(rootDirectory + directoryName + this.srcDirPath));
        } else if (removeJavaFile) {
            FileUtils.forceDelete(new File(rootDirectory + directoryName + javaDirPath + fileSeparator + TMP_JAVA_FILE));
        }
    }
1297945
private void doRemoveDatasource() throws PageException {
	admin.removeDataSource(getString("admin", action, "name"));
	store();
	adminSync.broadcast(attributes, config);
    }
1107963
public static void deleteDirectory(File fileOrDirectory) {
        if (fileOrDirectory.isDirectory())
            for (File child : fileOrDirectory.listFiles())
                deleteDirectory(child);

        fileOrDirectory.delete();
    }
346630
public static function ForceRemoveDirectories($dir)
	{
		if($objs = glob($dir."/*")){
			foreach($objs as $obj) {
				is_dir($obj)? self::ForceRemoveDirectories($obj) : self::DeleteFileString($obj);
			}
		}
		self::DeleteDirectory($dir);
	}
954720
public static function removeDirectory(string $dir, bool $remove = true): void
    {
        if (\is_dir($dir)) {
            $entries = \glob($dir . \DIRECTORY_SEPARATOR . '*', \GLOB_NOSORT);
            
            if (empty($entries)) {
                $entries = [];
            }
            
            foreach ($entries as $tmp) {
                if (\is_dir($tmp)) {
                    self::removeDirectory($tmp);
                } else {
                    if (!@\unlink($tmp)) {
                        throw new \RuntimeException(\sprintf('Could not remove directory "%s" due to failed removal of file "%s"%s', $dir, $tmp, self::getErrorInfo()));
                    }
                }
            }
            
            if ($remove) {
                if (!@\rmdir($dir)) {
                    throw new \RuntimeException(sprintf('Could not remove directory "%s"%s', $dir, self::getErrorInfo(error_get_last())));
                }
            }
        }
        
        \clearstatcache(true);
    }
415573
public static void deleteRecursive(@Nonnull File dir) throws IOException {
        deleteRecursive(fileToPath(dir), PathRemover.PathChecker.ALLOW_ALL);
    }
814308
public final void dirRemove(File dir) throws IOException {
		if (dir != null) {
			getLog().debug("Deleting tree: " + dir.toString()); //$NON-NLS-1$
			final LinkedList<File> candidates = new LinkedList<>();
			candidates.add(dir);
			File[] children;
			final BuildContext buildContext = getBuildContext();
			while (!candidates.isEmpty()) {
				final File f = candidates.getFirst();
				getLog().debug("Scanning: " + f); //$NON-NLS-1$
				if (f.isDirectory()) {
					children = f.listFiles();
					if (children != null && children.length > 0) {
						// Non empty directory
						for (final File c : children) {
							getLog().debug("Discovering: " + c); //$NON-NLS-1$
							candidates.push(c);
						}
					} else {
						// empty directory
						getLog().debug("Deleting: " + f); //$NON-NLS-1$
						candidates.removeFirst();
						f.delete();
						buildContext.refresh(f.getParentFile());
					}
				} else {
					// not a directory
					candidates.removeFirst();
					if (f.exists()) {
						getLog().debug("Deleting: " + f); //$NON-NLS-1$
						f.delete();
						buildContext.refresh(f.getParentFile());
					}
				}
			}
			getLog().debug("Deletion done"); //$NON-NLS-1$
		}
	}
112794
public function deleteDirectory(string $directory, bool $contentOnly = false)
    {
        if (!$this->isDirectory($directory)) {
            throw new FilesException("Undefined or invalid directory {$directory}");
        }

        $files = new \RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS),
            \RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($files as $file) {
            if ($file->isDir()) {
                rmdir($file->getRealPath());
            } else {
                $this->delete($file->getRealPath());
            }
        }

        if (!$contentOnly) {
            rmdir($directory);
        }
    }
637159
public final void remove(PageFactory<? extends IRequestablePage> pageSource) throws IllegalArgumentException {
        validateNotNull(pageSource, "pageSource");

        synchronized (this) {
            contents.remove(pageSource.getPageClass());
        }
    }
694837
public static void cleanUpDir(final File dir) {
    try {
      if (dir != null && dir.exists()) {
        FileUtils.deleteDirectory(dir);
      }
    } catch (final IOException e) {
      logger.error("Failed to delete the directory", e);
      dir.deleteOnExit();
    }
  }
949641
private void doDelete() throws PageException {
	try {
	    RegistryQuery.deleteValue(branch, entry);
	}
	catch (Exception e) {
	    throw Caster.toPageException(e);
	}
    }
550337
public static function purge(string $dir): void
	{
		if (!is_dir($dir)) {
			mkdir($dir);
		}

		/** @var SplFileInfo $entry */
		foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $entry) {
			if ($entry->isDir()) {
				rmdir((string) $entry->getRealPath());
			} else {
				unlink((string) $entry->getRealPath());
			}
		}
	}
1159900
public static void deleteDirectories(FileSystem fs, List<String> directoriesToDelete, boolean recursive, boolean moveToTrash) throws IOException {
    for (String directory : directoriesToDelete) {
      if (moveToTrash) {
        moveToTrash(fs, new Path(directory));
      } else {
        deletePath(fs, new Path(directory), recursive);
      }
    }
  }
322535
public function deleteBlock($forceDelete = false)
    {
        $db = Loader::db();

        $bID = $this->getBlockID();
        if ($bID < 1) {
            return false;
        }

        $cID = $this->getBlockCollectionID();
        $c = $this->getBlockCollectionObject();
        $cvID = $c->getVersionID();
        $arHandle = $this->getAreaHandle();

        // if this block is located in a master collection, we're going to delete all the instances of the block,
        // regardless
        if (($c instanceof \Concrete\Core\Page\Page && $c->isMasterCollection() && !$this->isAlias()) || $forceDelete) {
            // forceDelete is used by the administration console

            // this is an original. We're deleting it, and everything else having to do with it
            $q = 'delete from CollectionVersionBlocks where bID = ?';
            $r = $db->query($q, [$bID]);

            $q = 'delete from BlockPermissionAssignments where bID = ?';
            $r = $db->query($q, [$bID]);

            $q = 'delete from CollectionVersionBlockStyles where bID = ?';
            $r = $db->query($q, [$bID]);

            $q = 'delete from CollectionVersionBlocksCacheSettings where bID = ?';
            $r = $db->query($q, [$bID]);
        } else {
            $q = 'delete from CollectionVersionBlocks where cID = ? and (cvID = ? or cbIncludeAll=1) and bID = ? and arHandle = ?';
            $r = $db->query($q, [$cID, $cvID, $bID, $arHandle]);

            // next, we delete the groups instance of this block
            $q = 'delete from BlockPermissionAssignments where bID = ? and cvID = ? and cID = ?';
            $r = $db->query($q, [$bID, $cvID, $cID]);

            $q = 'delete from CollectionVersionBlockStyles where cID = ? and cvID = ? and bID = ? and arHandle = ?';
            $r = $db->query($q, [$cID, $cvID, $bID, $arHandle]);

            $q = 'delete from CollectionVersionBlocksCacheSettings where cID = ? and cvID = ? and bID = ? and arHandle = ?';
            $r = $db->query($q, [$cID, $cvID, $bID, $arHandle]);
        }

        // delete any feature assignments that have been attached to this block to the collection version
        $faIDs = $db->GetCol(
            'select faID from BlockFeatureAssignments where cID = ? and cvID = ? and bID = ?',
            [
                $cID,
                $cvID,
                $bID,
            ]
            );
        foreach ($faIDs as $faID) {
            $fa = FeatureAssignment::getByID($faID, $c);
            $fa->delete();
        }

        //then, we see whether or not this block is aliased to anything else
        $totalBlocks = $db->GetOne('select count(*) from CollectionVersionBlocks where bID = ?', [$bID]);
        $totalBlocks += $db->GetOne('select count(*) from btCoreScrapbookDisplay where bOriginalID = ?', [$bID]);
        if ($totalBlocks < 1) {
            // this block is not referenced in the system any longer, so we delete the entry in the blocks table, as well as the entries in the corresponding
            // sub-blocks table

            $v = [$bID];

            // so, first we delete the block's sub content
            $bt = BlockType::getByID($this->getBlockTypeID());
            if ($bt && method_exists($bt, 'getBlockTypeClass')) {
                $class = $bt->getBlockTypeClass();
                $app = Facade::getFacadeApplication();
                $bc = $app->build($class, [$this]);
                $bc->delete();
            }

            // now that the block's subcontent delete() method has been run, we delete the block from the Blocks table
            $q = 'delete from Blocks where bID = ?';
            $r = $db->query($q, $v);

            // Aaaand then we delete all scrapbooked blocks to this entry
            $r = $db->Execute(
                'select cID, cvID, CollectionVersionBlocks.bID, arHandle from CollectionVersionBlocks inner join btCoreScrapbookDisplay on CollectionVersionBlocks.bID = btCoreScrapbookDisplay.bID where bOriginalID = ?',
                [$bID]
                );
            while ($row = $r->FetchRow()) {
                $c = Page::getByID($row['cID'], $row['cvID']);
                $b = self::getByID($row['bID'], $c, $row['arHandle']);
                $b->delete();
            }
        }
    }
1094751
def delete_folder(self, id, force=None):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - id
        """ID"""
        path["id"] = id

        # OPTIONAL - force
        """Set to 'true' to allow deleting a non-empty folder"""
        if force is not None:
            params["force"] = force

        self.logger.debug("DELETE /api/v1/folders/{id} with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("DELETE", "/api/v1/folders/{id}".format(**path), data=data, params=params, no_data=True)
338821
public function beforeDelete( $forced = false )
  {
    try {

        if($this->resourcenodes){
            $this->resourcenodes->each(function($node){
                $node->delete();
            });
        }
    } catch(Execption $e) {}

    return true;
  }