I have a question about the following script in Tutorial 4-1 of the Esri Advanced Guide to Python book: when I run it, it produces a "FileExistsError"; the script is in fact creating a new folder and a duplicate .gdb file, but I don't know why. Below is the portion in question with the subsequent error message. Thanks!
source_fgdb_path = Path(r".\Parking_Violations_and_Neighborhoods.gdb")
arcpy.management.Compact(str(source_fgdb_path))
# The name of the folder to place the file geodatabase in
fgdb_folder_name = source_fgdb_path.stem
# The location of the folder to place the file geodatabase in
fgdb_folder_location = source_fgdb_path.parent
# The path to the folder to place the file geodatabase in
fgdb_folder_path = fgdb_folder_location.joinpath(fgdb_folder_name)
# The path of our copied file geodatabase
fgdb_path = fgdb_folder_path.joinpath(source_fgdb_path.name)
# Copy the file geodatabase to the new location
shutil.copytree(source_fgdb_path, fgdb_path)
# Zip the file geodatabase
zipped_fgdb = shutil.make_archive(
base_name=fgdb_folder_path,
# The name of the archive, not including the file extension
format="zip", # The archive format
root_dir=fgdb_folder_path, # The directory to archive
)
--------------------------------------------------------------------------- FileExistsError Traceback (most recent call last) Cell In[7], line 2 1 # Copy the file geodatabase to the new location ----> 2 shutil.copytree(source_fgdb_path, fgdb_path) 3 # Zip the file geodatabase 4 zipped_fgdb = shutil.make_archive( 5 base_name=fgdb_folder_path, 6 # The name of the archive, not including the file extension 7 format="zip", # The archive format 8 root_dir=fgdb_folder_path, # The directory to archive 9 ) File ~\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\shutil.py:573, in copytree(src, dst, symlinks, ignore, copy_function, ignore_dangling_symlinks, dirs_exist_ok) 571 with os.scandir(src) as itr: 572 entries = list(itr) --> 573 return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks, 574 ignore=ignore, copy_function=copy_function, 575 ignore_dangling_symlinks=ignore_dangling_symlinks, 576 dirs_exist_ok=dirs_exist_ok) File ~\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\shutil.py:471, in _copytree(entries, src, dst, symlinks, ignore, copy_function, ignore_dangling_symlinks, dirs_exist_ok) 468 else: 469 ignored_names = () --> 471 os.makedirs(dst, exist_ok=dirs_exist_ok) 472 errors = [] 473 use_srcentry = copy_function is copy2 or copy_function is copy File <frozen os>:225, in makedirs(name, mode, exist_ok) FileExistsError: [WinError 183]