Page 1 of 1

how to delete files from root dir.

Posted: Fri Feb 10, 2006 7:05 am
by itsmani1
i want to delete all .html and .htm files from root directory
how can i do so?

one morething is
i want to convert my php extension to html for example
http://maair.net/content.php i want to convert it to .html but it should work as it is working Dynamically

thanks

Posted: Fri Feb 10, 2006 8:31 am
by feyd
glob() or opendir()-readdir() to build a file list, unlink() to delete. Be aware: it will not be able to delete files it doesn't have permission to.

You have to add .html as a php parsed type then rename the file. Be aware that all .html files, whether they have php in them or not, will be processed by php.

Re: how to delete files from root dir.

Posted: Fri Feb 10, 2006 8:40 am
by SKDevelopment
It would be advisable also to replace the unlink() command with echo and see which files your script is going to delete before you do any actual deleting.

--
Best Regards,
Sergey Korolev
www.skdevelopment.com

Posted: Wed Feb 15, 2006 7:27 am
by itsmani1
well, actually i want to delete all .html files
is there any command or function by calling which i can delete all .html files in a specfic directory

thanks.
Mannan.

Posted: Thu Feb 16, 2006 12:12 am
by itsmani1
one small question!

how can i selete all files in a specfic directory, means i want to select all files in an array etc how can i do so?

Posted: Thu Feb 16, 2006 12:14 am
by Christopher
feyd wrote:glob() or opendir()-readdir() to build a file list, unlink() to delete.
Look in these sections of the PHP manual. There are good examples there.

Posted: Thu Feb 16, 2006 12:38 am
by josh

Code: Select all

echo ` rm -rf /path/*.html`;
be careful with that one :)

Posted: Thu Feb 16, 2006 12:50 am
by s.dot
using apache?

you could use a mod rewrite (assuming all .html files are .php) and give the illusion that it's an .html file (don't know if that's what you're going for).

.htaccess file

Code: Select all

RewriteEngine On

RewriteRule ^(.+)\.html$ $1\.php

Posted: Thu Feb 16, 2006 12:55 am
by itsmani1

Code: Select all

$dir = "../";
if (is_dir($dir)) {
   if ($dh = opendir($dir))
   {
		foreach (glob("*.html") as $filename)
		{
			unlink($filename);
		}
   }
}
directory strucure is like this:
abc/xyz

i am in xyz rign now and want to delete all .html files of abc

Posted: Thu Feb 16, 2006 2:20 am
by Chris Corbyn
itsmani1 wrote:

Code: Select all

$dir = "../";
if (is_dir($dir)) {
   if ($dh = opendir($dir))
   {
		foreach (glob("*.html") as $filename)
		{
			unlink($filename);
		}
   }
}
directory strucure is like this:
abc/xyz

i am in xyz rign now and want to delete all .html files of abc
This won't work if the files were uploaded by FTP. You'll need to CHMOD them first.

Note your path to unlink is wrong. You need to prepend the $dir too.

Posted: Thu Feb 16, 2006 2:24 am
by feyd
psst, glob() returns full path d

;)

Posted: Thu Feb 16, 2006 2:59 am
by Chris Corbyn
feyd wrote:psst, glob() returns full path d

;)
:oops: Do check the permissions though itsmani

Posted: Thu Feb 23, 2006 4:33 am
by itsmani1
well files are not uploaded via ftp, there are generated via script.

Posted: Thu Feb 23, 2006 4:39 am
by itsmani1
my main question is how do i move the directory which parent of current direcoty
for example i am in xyz dir which is like this ../abc/xyz
i want to move to ../abc how do i move using golb()