<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1028833" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1028833</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/script-delete-file-tree#comment-1169335</link>
    <description> &lt;p&gt;Here is what I ended up throwing together for my use in case anyone ever comes across this thread needing something similar.&lt;/p&gt;
&lt;p&gt; This script just deleted any log files over a week old in the directories starting with IP_ (indicates not logged in as a user). And then if that directory becomes empty after deleting the files, then it will delete the directory as well.&lt;/p&gt;
&lt;p&gt;  Enjoy, let me know if you have any questions using/modifying it.&lt;/p&gt;
&lt;p&gt;  -Greg&lt;/p&gt;
&lt;p&gt; PS. Note that I am using PHP 4.something, so I couldn&#039;t the &lt;strong&gt;scandir&lt;/strong&gt; function built into version 5. I wrote my own and added a little extra:&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;$path&lt;/strong&gt; = (string) the path you are wanting a listing of&lt;br /&gt;
 &lt;strong&gt;$incRel&lt;/strong&gt; = (true/false) should include &quot;.&quot; and &quot;..&quot; in the list&lt;br /&gt;
 &lt;strong&gt;$getWhat&lt;/strong&gt; = (&#039;d&#039;,&#039;f&#039;,&#039;b&#039;) entriest to list, &lt;strong&gt;d&lt;/strong&gt;irectories, &lt;strong&gt;f&lt;/strong&gt;iles, or &lt;strong&gt;b&lt;/strong&gt;oth&lt;br /&gt;
 RETURNS: Array of the filenames (and direcotry names) in the path specified&lt;/p&gt;
&lt;p&gt;  &lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;lt;?&lt;br /&gt;&amp;nbsp; function scandir2($path,$incRel=true,$getWhat=&amp;#039;b&amp;#039;)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $dirList = array();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $dirHand = opendir($path);&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (false !== ($file = readdir($dirHand)))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp; 	if (is_dir($path . &amp;quot;/&amp;quot; . $file))&lt;br /&gt;&amp;nbsp; 	{&lt;br /&gt;&amp;nbsp; 	&amp;nbsp; if ($getWhat != &amp;#039;f&amp;#039;)&lt;br /&gt;&amp;nbsp; 		if ($file == &amp;quot;.&amp;quot; || $file == &amp;quot;..&amp;quot;)&lt;br /&gt;&amp;nbsp; 		&amp;nbsp; { if ($incRel) $dirList[] = $file; }&lt;br /&gt;&amp;nbsp; 		else&lt;br /&gt;&amp;nbsp; 		&amp;nbsp; $dirList[] = $file;&lt;br /&gt;&amp;nbsp; 	}&lt;br /&gt;&amp;nbsp; 	else&lt;br /&gt;&amp;nbsp; 	&amp;nbsp;&amp;nbsp; if ($getWhat != &amp;#039;d&amp;#039;)&lt;br /&gt;&amp;nbsp; 		 $dirList[] = $file;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; closedir($dirHand);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $dirList;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; $basePath = &amp;quot;/base/dir/path/without/trailing/slash&amp;quot;;&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; $lastWeek = mktime(0, 0, 0, date(&amp;quot;m&amp;quot;), date(&amp;quot;d&amp;quot;)-7,&amp;nbsp; date(&amp;quot;Y&amp;quot;));&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; $rootDir = scandir2($basePath,false,&amp;#039;d&amp;#039;);&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; foreach ($rootDir as $thisDir) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (substr($thisDir,0,3)==&amp;quot;IP_&amp;quot;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp; 	$subDir = scandir2($basePath . &amp;quot;/&amp;quot; . $thisDir,false,&amp;#039;f&amp;#039;);&lt;br /&gt;&amp;nbsp; 	$canDelete = true;&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; 	foreach ($subDir as $thisFile) &lt;br /&gt;&amp;nbsp; 	{&lt;br /&gt;&amp;nbsp; 	&amp;nbsp; $fullFile = $basePath . &amp;quot;/&amp;quot; . $thisDir . &amp;quot;/&amp;quot; . $thisFile;&lt;br /&gt;&amp;nbsp; 	&amp;nbsp; if (filemtime($fullFile)&amp;lt;$lastWeek)&lt;br /&gt;&amp;nbsp; 		unlink($fullFile);&lt;br /&gt;&amp;nbsp; 	&amp;nbsp; else &lt;br /&gt;&amp;nbsp; 		$canDelete = false;&lt;br /&gt;&amp;nbsp; 	}&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; 	if ($canDelete)&lt;br /&gt;&amp;nbsp; 	&amp;nbsp; rmdir($basePath . &amp;quot;/&amp;quot; . $thisDir);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; ?&amp;gt;&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
 </description>
     <pubDate>Sun, 10 Apr 2005 03:11:43 +0000</pubDate>
 <dc:creator>Greg K</dc:creator>
 <guid isPermaLink="false">comment 1169335 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/script-delete-file-tree#comment-1169280</link>
    <description> &lt;p&gt;Yeah, but i have to write a scrip to dothis every so often anyhow. Once it is up and running, will have it run as cron each night.&lt;/p&gt;
&lt;p&gt;-Greg&lt;/p&gt;
 </description>
     <pubDate>Fri, 08 Apr 2005 18:51:40 +0000</pubDate>
 <dc:creator>Greg K</dc:creator>
 <guid isPermaLink="false">comment 1169280 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/script-delete-file-tree#comment-1169277</link>
    <description> &lt;p&gt;Easiest solution would be to contact your host and get them to log in as root and delete the files. It will only take them a couple of seconds.&lt;/p&gt;
 </description>
     <pubDate>Fri, 08 Apr 2005 16:23:02 +0000</pubDate>
 <dc:creator>andy206uk</dc:creator>
 <guid isPermaLink="false">comment 1169277 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
