Python Forum
copy paste file and re-name it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
copy paste file and re-name it
#1
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?
Reply
#2
If you get "permission denied error", you probably need admin rights.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy Paste excel files based on the first letters of the file name Viento 2 348 Feb-07-2024, 12:24 PM
Last Post: Viento
  What script to paste folders thenewcoder 1 639 Nov-29-2023, 09:40 AM
Last Post: Pedroski55
  Copy data from Excel and paste into Discord (Midjourney) Joe_Wright 4 1,925 Jun-06-2023, 05:49 PM
Last Post: rajeshgk
  is it possible to copy image from email and place into excel file? cubangt 3 1,212 Nov-30-2022, 05:11 PM
Last Post: snippsat
  Please help me [copy and paste file from src to dst] midomarc 2 961 Nov-24-2022, 10:13 PM
Last Post: midomarc
  ImageTk Paste KDog 14 6,745 Jun-27-2021, 11:07 AM
Last Post: KDog
  Copy column from one existing excel file to another file mkujawsk 0 5,486 Apr-14-2021, 06:33 PM
Last Post: mkujawsk
  Cut and Paste Oshadha 3 2,386 Jan-20-2021, 04:27 PM
Last Post: spaceraiders
  Failing to copy file from a network to a local drive tester_V 4 6,974 Jan-20-2021, 07:40 AM
Last Post: tester_V
  Copy mp3 file multiple times and rename Mar10 4 3,676 Sep-23-2020, 01:09 AM
Last Post: Mar10

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020