Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>File deleter</title>
- </head>
- <body>
- <h1>This page should delete all files in the specified folders, except the specified file names. In theory. Not tested.</h1>
- <?php
- $CompletePath=true;
- //Change the above to false if your folders are all in the same parent folder. True means that yes, you're going to give complete paths in $FolderList.
- $FolderList=array(
- "FOLDER 1",
- "FOLDER 2",
- "FOLDER 3"
- //[...]
- );
- //Place all of your folders above. Make sure each folder is between quotes, and each of them EXCEPT THE LAST is followed by a comma.
- //If your folders are NOT in the same parent folder, what you should put between the quotes is their full path name, starting with C:\ or whatever your drive is.
- if($CompletePath==false) {
- $ParentPath="C:\Users\Administrator\Documents\Your parent folder";
- }
- //If all of your folders DO have the same parent folder, put the path to the parent folder in question here. Having the same parent folder means they're inside the same folder, side by side. If not, don't worry about it, it won't even be read.
- $FilesToSave=array(
- "FILE 1.txt",
- "FILE 2.rar",
- "FILE 3.png"
- );
- //Put the file names you do NOT want to delete here. Make sure each file is between quotes, and each of them EXCEPT THE LAST is followed by a comma. File names only. No folders.
- //------------------You're done with the settings. Below is just code. You should be able to run this now, with WAMP.---------------------//
- foreach($FolderList as $Path) {
- if($CompletePath==true) {
- $Path=$ParentPath.$Path;
- }
- $D_Folder=opendir($Path);
- while($File=readdir($D_Folder)) {
- if($File!='.' && $File!='..' && $File!='Thumbs.db') {
- $OkayToDelete=true;
- $FileNb=0;
- while($FileNb<count($FilesToSave) && $OkayToDelete==true) {
- if($File==$FilesToSave[$FileNb]) {
- $OkayToDelete=false;
- }
- }
- if($OkayToDelete==true) {
- if(is_readable(realpath($Path.'\\'.$File)) {
- if(unlink($Path)) {
- echo '
- <p>File "'.realpath($Path.'\\'.$File).'" was successfully deleted.</p>
- ';
- }
- else {
- echo '
- <p>Unable to delete file "'.realpath($Path.'\\'.$File).'". Either such a file does not exist, either an unknown error has occurred.</p>
- ';
- }
- }
- else {
- echo '
- <p>Unable to read file "'.realpath($Path.'\\'.$File).'".</p>
- ';
- }
- }
- else {
- echo '
- <p>File "'.realpath($Path.'\\'.$File).'" was not deleted because it was defined as a file to save.</p>
- ';
- }
- }
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement