create php script that remove all other folders and only keep "real" folder and ".app"…
- User
create php script that remove all other folders and only keep "real" folder and ".app" and other files
- Assistant
Here is a PHP script that removes all folders except the "real" folder and keeps all files including those in ".app", while preserving the current working directory:
<?php $currentDir = getcwd(); $folders = scandir($currentDir); foreach ($folders as $folder) { if ($folder != "." && $folder != ".." && $folder != "real" && is_dir($folder)) { rrmdir($currentDir . "/" . $folder); } } function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (is_dir($dir."/".$object)) rrmdir($dir."/".$object); else unlink($dir."/".$object); } } rmdir($dir); } } ?>This loops through all folders in the current directory, and removes them with a recursive delete function, except for "." , ".." and "real". It leaves all files intact, including those in ".app".
The working directory remains unchanged, so this should safely clean out other folders while preserving the ones you want to keep.
- User
create php script that remove all other folders and only keep "real" folder and ".app" folder and index.php
- Assistant
Here is the updated PHP script to remove all folders except "real" and ".app", while keeping the index.php file:
<?php $currentDir = getcwd(); $protectedFolders = array('.app', 'real'); $protectedFiles = array('index.php'); $folders = scandir($currentDir); foreach ($folders as $folder) { if ($folder != "." && $folder != ".." && !in_array($folder, $protectedFolders) && is_dir($folder)) { rrmdir($currentDir . "/" . $folder); } } function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != ".." && !in_array($object, $protectedFiles)) { if (is_dir($dir."/".$object)) rrmdir($dir."/".$object); else unlink($dir."/".$object); } } rmdir($dir); } } ?>The changes:
- Added a $protectedFolders array with "real" and ".app"
- Added a $protectedFiles array with "index.php"
- Check if the folder or file is in those arrays before deleting
This will now keep "real", ".app" folders and index.php file, while removing everything else.
- User
PHP script to remove all folders except "real" and ".app", and keeping the index.php file
- Assistant
Here is the PHP script to remove all folders except "real" and ".app", while keeping the index.php file:
<?php $protectedFolders = array('real', '.app'); $protectedFiles = array('index.php'); $currentDir = getcwd(); $folders = scandir($currentDir); foreach ($folders as $folder) { $path = $currentDir . '/' . $folder; if (!in_array($folder, array('.', '..')) && !in_array($folder, $protectedFolders) && is_dir($path)) { deleteFolder($path); } } function deleteFolder($path) { $files = scandir($path); foreach($files as $file) { $file = $path . '/' . $file; if (!in_array($file, array('.', '..')) && !in_array(basename($file), $protectedFiles)) { if(is_dir($file)) { deleteFolder($file); } else { unlink($file); } } } rmdir($path); } ?>The key points:
- $protectedFolders array with 'real' and '.app'
- $protectedFiles array with 'index.php'
- Recursively delete folders not in protected folders
- Don't delete protected files
- Keeps working directory intact
Let me know if you have any other questions!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.