Merge Folders

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Merge Folders

Postby decompile » Sat Oct 02, 2021 1:23 am

Hey!

I'm currently trying to write an updater for my plugin and I encountered a problem.

So what it basically does is download the master version, unzip it into a temporary folder, remove existing files and then extract the unzipped files to the server files.

Syntax: Select all

from distutils.dir_util import copy_tree
from paths import GAME_PATH

SOURCE_PATH = GAME_PATH / "update"

copy_tree(SOURCE_PATH, GAME_PATH)


The only problem with this is, if SOURCE_PATH contains a newly created directory, which does not exist in GAME_PATH, it raises:

SOURCE_PATH:
../source-python/packages/custom/certifi/cacert.pem

GAME_PATH:
../source-python/packages/custom


Code: Select all

distutils.errors.DistutilsFileError: could not create '..\addons\source-python\packages\custom\certifi\cacert.pem': No such file or directory


Is there a possible way to create all missing directories and sub-directories of SOURCE_PATH e.g: ../addons/source-python or ..addons/source-python/custom/certifi or is there maybe even a better way to extract SOURCE_PATH into GAME_PATH
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Merge Folders

Postby L'In20Cible » Sat Oct 02, 2021 8:41 am

Syntax: Select all

SOURCE_PATH.copytree(GAME_PATH)
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Merge Folders

Postby decompile » Sat Oct 02, 2021 12:55 pm

L'In20Cible wrote:

Syntax: Select all

SOURCE_PATH.copytree(GAME_PATH)


Sadly results in an FileExistsError:

NEW_UPDATE_PATH.copytree(GAME_PATH)
File "..\addons\source-python\Python3\shutil.py", line 315, in copytree
os.makedirs(dst)
File "..\addons\source-python\Python3\os.py", line 220, in makedirs
mkdir(name, mode)

FileExistsError: [WinError 183] Cannot create a file when that file already exists: Path('D:\\GameServer\\css_tricksurf\\cstrike')
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Merge Folders

Postby satoon101 » Sat Oct 02, 2021 4:51 pm

Unfortunately, I don't think we have updated SP to Python3.8 (iirc). If we did, this would work:
https://stackoverflow.com/a/58916847

But, there are other answers on that SO thread that you might try.
Image
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Merge Folders

Postby decompile » Sat Oct 02, 2021 6:40 pm

Thanks!

I'm gonna try this:
https://stackoverflow.com/a/22331852
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Merge Folders

Postby L'In20Cible » Sat Oct 02, 2021 9:51 pm

decompile wrote:
L'In20Cible wrote:

Syntax: Select all

SOURCE_PATH.copytree(GAME_PATH)


Sadly results in an FileExistsError:

NEW_UPDATE_PATH.copytree(GAME_PATH)
File "..\addons\source-python\Python3\shutil.py", line 315, in copytree
os.makedirs(dst)
File "..\addons\source-python\Python3\os.py", line 220, in makedirs
mkdir(name, mode)

FileExistsError: [WinError 183] Cannot create a file when that file already exists: Path('D:\\GameServer\\css_tricksurf\\cstrike')


Sorry, didn't look close enough at your paths. The problem is that your source is inside your destination. Using merge_tree instead of copytree should do the trick.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Merge Folders

Postby decompile » Tue Oct 05, 2021 3:55 pm

Works perfectly, thanks!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 19 guests