Use dirname instead of basename. Differentiate between mv and ln.