Hi I cannot figure out why the rename function is not working as I think it should. Every aspect of the script seems to be working except for the rename function while inside the loop. <?php // open the current directory $dhandle = opendir('.'); $rename = rename('test', 'wtfthisworks'); // changing directory test to wtfthisworks works!! if ($dhandle) { // loop through all of the files while (false !== ($fname = readdir($dhandle))) { // if the file is not this file, and does not start with a '.' or '..', and is a directory if (($fname != '.') && ($fname != '..') && ($fname != basename($_SERVER['PHP_SELF'])) && (is_dir($fname))) { $fname = trim($fname); $query = "'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_row($result); // query is working if ($row[0]) { $rename = rename('{$fname}', '{$row[0]}'); // this not working if($rename) { echo "success renaming {$fname} to {$row[0]} ! <br />"; } else { echo "Renaming {$fname} failed to {$row[0]} <br />"; // the loop and variable print as expected therefore query and loop works! } } } } // close the directory closedir($dhandle); } mysql_close($pfw_link); ?>