Page 1 of 1

What does it mean?

Posted: Sat Aug 24, 2002 1:21 pm
by rainbow
I'm working on a script which has been developed by another person. It deals with folder removing. Here is the part of code:

Code: Select all

if ($dir = @opendir("$dir2remove"))
{
    while (($file = readdir($dir)) !== false)
    {
          if (!($file=="." || $file==".." || $file=="index.html"))
          {
            chdir($version_depository."topic".$ct_topic_id."/".$file);
            system("rm *");

            chdir($version_depository."topic".$ct_topic_id."/");
            rmdir($file);
          }
    } //close while
    closedir($dir);
But i don't understand well the following line:
"system("rm *");" Does it mean to delete the folder? But the command for deleting folder is another. Ijust couldn't find anyting similiar in php manual. So can anyone help me?
"

Posted: Sat Aug 24, 2002 1:36 pm
by volka
system("rm *"); is similar to opening a new shell (or cmd/command.exe on win32) and execute the given command.
so 'rm *' will remove all files in the current directory on unix.
It does not recurse in sub directories ( rm -R * dos/win: del *.* , del /S *.* )

The script is dangerous in at least two ways:
- it doesn't check if chdir worked properly (bye bye script dir ;) )
- on some systems rm * is 'protected' by a confirmation question (are you sure? y/n)

Posted: Sat Aug 24, 2002 1:55 pm
by rainbow
Thanks a lot ! :)