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 and Paste Files - Command MicheliBarcello 2 848 Jun-25-2024, 05:04 AM
Last Post: rodiongork
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 1,283 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Copy Paste excel files based on the first letters of the file name Viento 2 1,488 Feb-07-2024, 12:24 PM
Last Post: Viento
  What script to paste folders thenewcoder 1 1,260 Nov-29-2023, 09:40 AM
Last Post: Pedroski55
  Copy data from Excel and paste into Discord (Midjourney) Joe_Wright 4 3,901 Jun-06-2023, 05:49 PM
Last Post: rajeshgk
  is it possible to copy image from email and place into excel file? cubangt 3 2,437 Nov-30-2022, 05:11 PM
Last Post: snippsat
  Please help me [copy and paste file from src to dst] midomarc 2 1,753 Nov-24-2022, 10:13 PM
Last Post: midomarc
  ImageTk Paste KDog 14 10,008 Jun-27-2021, 11:07 AM
Last Post: KDog
  Copy column from one existing excel file to another file mkujawsk 0 7,608 Apr-14-2021, 06:33 PM
Last Post: mkujawsk
  Cut and Paste Oshadha 3 3,276 Jan-20-2021, 04:27 PM
Last Post: spaceraiders

Forum Jump:

User Panel Messages

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