Do you have control over the application generating the files? You seem to have a few race conditions in your logic. What happens if the parent process the directory as files are created and spawns the child to process before the file is actually closed and static (this is an issue depending on the OS and or what the child actually does -- how does it handle broke/truncated files?). Also you have taken out the error code on the rename function -- I assume you handle duplicate file names in the fullpath/newpath locations well?