in reply to conveting .txt file to .dat

If you run this script from $runDir, you will wipe out your files without renaming them. If run from any other directory, it does achieve copying of the files to $runDir, but does so the hard way. Since you never give them new names, only a new directory, the names will stay the same. So, I conclude as my brethren have that this is not the script you need help with.

But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)