Your regex /\.*$/ will always match: it's looking for zero or more '.' characters at the end of the string. If you're attempting to eliminate the '.' and '..' directories you want:
if (!/^\.+$/) {
(String from start to end contains one or more '.' characters only)