So here is the problem, I have some path which is like this:
JavaScript
x
2
1
get_path = 'C:/Users/user1/Desktop/Files/File/1/category/UFF/'
2
Then I use this to “make” it win path:
JavaScript
1
2
1
path = pathlib.Path(get_path)
2
So now every time I use it, to create some other files inside of path directory, my files are created inside of “category” folder with prefix UFF, so file names are:
JavaScript
1
5
1
category folder:
2
3
UFFNameFile1.xml
4
UFFNameFile2.xml
5
instead of
JavaScript
1
5
1
UFF folder:
2
3
NameFile1.xml
4
NameFile2.xml
5
For creation of files I use:
JavaScript
1
2
1
tree.write(str(path)+name+'.xml', encoding='utf-8', xml_declaration=True)
2
Anyone has idea what is going on?
Advertisement
Answer
The last slash in get_path
is dropped when passing to Path
. The string you are passing to tree.write
is exactly what you are seeing: 'C:/Users/user1/Desktop/Files/File/1/category/UFFsomefilename.XML'
You can fix this as followed:
JavaScript
1
3
1
path_out = path / f'{name}.xml'
2
tree.write(path_out.as_posix(), encoding='utf-8', xml_declaration=True)
3