Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cut and Paste
#1
I have these folders,

my folder
~|--assets
~|~~~|--logo.ico
~|script.py

script.py and assets are in my folder
logo.ico is in assets folder.

How can I create a folder in %appdata% named my script
and put the assets folder, in the my script folder?

I tried using many ways. But it makes no sense, and gives and error all the time!
Reply
#2
You can use the copytree method from the shutil module.

Usage is as such: shutil.copytree("src", "dst")

import shutil
shutil.copytree("src/folder/path/", "dst/folder/path")
In your case, the src path should be the path to the assets folder, and the dst path should be the path to your User's AppData folder.
"C:/Users/<Username>/AppData/my_script"

Be warned, however, the path the folder is going to be copied to must not exist. the last segment of the path will become the name of the folder, so in my case, whatever "src/folder/path" leads to, will be copied to "path/to", and the folder will be named "path."
Oshadha likes this post
Reply
#3
(Jan-19-2021, 11:15 PM)spaceraiders Wrote: You can use the copytree method from the shutil module.

Usage is as such: shutil.copytree("src", "dst")

import shutil
shutil.copytree("src/folder/path/", "dst/folder/path")
In your case, the src path should be the path to the assets folder, and the dst path should be the path to your User's AppData folder.
"C:/Users/<Username>/AppData/my_script"

Be warned, however, the path the folder is going to be copied to must not exist. the last segment of the path will become the name of the folder, so in my case, whatever "src/folder/path" leads to, will be copied to "path/to", and the folder will be named "path."

how do i get the directorys, which changes from computer to computer!?
Reply
#4
If you're asking on how to get the AppData directory, I showed right here:
"C:/Users/<Username>/AppData/my_script"

All you must do is replace <Username> with your account's Username. However, I believe you can use os.getenv("APPDATA") to retrieve the path to the AppData directory.

import os
print(os.getenv("APPDATA"))
Oshadha likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What script to paste folders thenewcoder 1 639 Nov-29-2023, 09:40 AM
Last Post: Pedroski55
  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 paste file and re-name it asheru93 1 2,342 May-24-2019, 10:43 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

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