in reply to Re^4: help on this code below
in thread help on this code below

Do you at least check for the return value of rename? Have you studied its documentation?