Corrected initialization of pid and log paths

- Now correctly initializes the files path according to the index,
inserting it before the extension in all cases.