Python Forum
Cut and Paste - 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: Cut and Paste (/thread-32071.html)



Cut and Paste - Oshadha - Jan-19-2021

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!


RE: Cut and Paste - spaceraiders - Jan-19-2021

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."


RE: Cut and Paste - Oshadha - Jan-20-2021

(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!?


RE: Cut and Paste - spaceraiders - Jan-20-2021

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"))