You need to check movefile function which you used is OK or NG
- Original, after cd command.
2. after use movefile
3. after use rmdir
Because you jump to testpatient folder, so you can use rmdir('Opt_data') only.
If you still problem, if you can, please send me the source code, I want to see it