in reply to using unlink to delete files

AnonMonk above was pointing you in the right way. You seem to be trying to remove the stat'ed sizes, not the actual files. Plus readdir doesn't keep the file paths so even if you were doing unlink($f), it would fail unless you were in the right place. Look around in here for sample code for readdir if you get stuck.