Added condition to handle '~' in the filepath with formatted code