Python Forum
use of shutil.copytree with ENOTDIR exception
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
use of shutil.copytree with ENOTDIR exception
#2
(Nov-29-2023, 09:48 AM)yan Wrote: I would like to make a script to copy an entire tree for testing (folder, sub-folders, files).
I need all but the files are too big in the source and I don't need what's in them.
This is somewhat contradictory, but you could perhaps try the following
from pathlib import Path

def my_copy(src, dst):
    # create an empty file instead of actually copying a file
    Path(dst).touch()

# Source
src = '/mysourcepath'
  
# Destination
dest = '/mydestinationpath'
  
shutil.copytree(src, dest, dirs_exist_ok=True, copy_function=my_copy)
« We can solve any problem by introducing an extra level of indirection »
Reply


Messages In This Thread
RE: use of shutil.copytree with ENOTDIR exception - by Gribouillis - Nov-29-2023, 11:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  shutil.move make data corrupt kucingkembar 0 901 Feb-01-2023, 01:30 PM
Last Post: kucingkembar
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 5 1,815 Aug-28-2022, 07:11 AM
Last Post: Melcu54
  extra slashes in the network path for shutil.copy tester_V 3 3,951 Jun-02-2021, 07:57 AM
Last Post: supuflounder
  concatenat - shutil jmabrito 3 2,319 Feb-11-2021, 12:17 PM
Last Post: jmabrito
  Shutil FileNotFoundError: Errno 2 Help lord_kaiser 8 10,932 Aug-10-2020, 08:45 AM
Last Post: lord_kaiser
  shutil.copy questions kristianpython 3 2,427 Jul-14-2020, 09:19 AM
Last Post: Gribouillis
  Shutil move if file exists in destination Friend 2 7,026 Feb-02-2020, 01:45 PM
Last Post: Friend
  Shutil attempts to copy directories that don't exist ConsoleGeek 5 4,781 Oct-29-2019, 09:26 PM
Last Post: Gribouillis
  Sutil.copytree, I'm getting File Exists. Mike Ru 1 8,821 Oct-28-2019, 07:40 AM
Last Post: Gribouillis
  Help copying files with shutil hikerguy62 2 4,490 Aug-02-2019, 08:16 PM
Last Post: hikerguy62

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020