Python Forum

Full Version: Cut and Paste
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!
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."
(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!?
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"))