You can use
find instead of your shell:
find . -mindepth 1 -maxdepth 1 ! -name "*.dmg" -delete
! expr True if expr is false. This character will also usually need
protection from interpretation by the shell.
Base of file name (the path with the leading directories removed)
matches shell pattern pattern.
Delete files; true if removal succeeded. If the removal failed,
an error message is issued. If -delete fails, find's exit status
will be nonzero (when it eventually exits). Use of -delete
automatically turns on the -depth option.
If you can't use
find for whatever reason, here's a way to do it with
zsh (or other shells).
zsh, there is probably a simpler way of doing this but since I'm a
bash guy, this is what I came up with:
for file in *; do if [[ ! "$file" == *.dmg ]]; then rm $file; fi; done