Better removing of . and .. entries from the list of files

In some cases . and .. might not be the first two entries in the list that scandir($dir) returns, so it's safer to remove them specifically in the foreach loop. The special case is for example a filename beginning with a space.
Also making creation of $partialname safer when just replacing part of the string rather then re-creating it again which possibly gives different results.