copy paste file and re-name it - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: copy paste file and re-name it (/thread-16751.html) |
copy paste file and re-name it - asheru93 - Mar-13-2019 Hello, I am building some automated tests including install/uninstall of an app. I need to build a small back-up file system for a file. I have a file called User.gdh inside this folder: - C:\ProgramData\MyProgram\Database , so basically the full path is this C:\ProgramData\MyProgram\Database\User.gdh I want to create a copy of this file inside the same folder that will be called User.gdh.testcopy. Now if User.gdh.testcopy exists in this folder, I want to copy it over User.gdh. If User.gdh.testcopy does not exists in folder(this will happen only after a freshInstall of my tested program), I want to copy it from User.gdh and name with test copy inside the same folder. I've tried this: def userGdhBackup(): userGdhPath = C:\ProgramData\MyProgram\Database\User.gdh userGdhTestCopy = C:\ProgramData\MyProgram\Database\User.gdh.testcopy if os.path.isfile(userGdhTestCopy): shutil.copy(userGdhTestCopy,userGdhPath) else: shutil.move(userGdhPath,userGdhTestCopy)I guess this is not quite good and I am also getting "Permission denied error" What would be the best solution here? RE: copy paste file and re-name it - heiner55 - May-24-2019 If you get "permission denied error", you probably need admin rights. |