Didn't work likely due to the fact that "\\" is special. symbol. Used to refer to such things as end-of-line (\), tab (\\t). In Your case, most likely trying to understand what it means to \\d, \\G, etc. To write the \\ character in strings, use \\\\.
Depending on the version of Python may be a problem in the encoding path. Because there is a difference of Russian characters in cp1251 and UTF8 which is usually used in Windows.
I would write this:
import os from shutil import copyfile, rmtree SOURCE = 'D:\\\\домашка\\\\G_ Arhangelskiy_-_Time_Draive\\\\G_ Arhangelskiy_-_Time_Draive' DESTINATION = 'D:\\\\домашка\\\\G_ Arhangelskiy_-_Time_Draive\\\\G_ Arhangelskiy_-_Time_Draive — copy' files = [f.path for f in os.scandir(SOURCE) if f.is_file()] for file in files: copyfile(file, DESTINATION) rmtree(SOURCE)
How experienced Python developers can give some advice:
- Duplicate values in a separate variable (it would be better in a constant, but Python does not have constants). It's about the way the source that I have identified in the SOURCE (there is such an agreement, immutable variables when writing the title)
- To delete a path recursively, is in shutils module rmtree and os.scandir more convenient than os.listdir
- Install Linter (flake8), and then configure your editor to use it. Code shows that don't use the Linter