Note quite sure what it does, but stored proc could be simplified as follows (yes?):
Create PROC USP_ALTEROBJECTS @dbname varchar(100) = ''
as
BEGIN
DECLARE @filename VARCHAR(255)
SELECT @FileName = SUBSTRING(path, 0, LEN(path)-CHARINDEX('\', REVERSE(path))+1)...