Hello,
First thank you to help people !
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.
So I would like to copy the names of the files to recreate them empty in the destination folders.
With copytree, the copy works.
I was thinking of using the ENOTDIR exception to prevent files from being copied, retrieve their name and then create the empty equivalent file in the destination.
But for the moment, it does not take into account my exception and the copy is just done in full without error.
Could you help me please ?
Thank you.
First thank you to help people !
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.
So I would like to copy the names of the files to recreate them empty in the destination folders.
With copytree, the copy works.
I was thinking of using the ENOTDIR exception to prevent files from being copied, retrieve their name and then create the empty equivalent file in the destination.
But for the moment, it does not take into account my exception and the copy is just done in full without error.
Could you help me please ?
Thank you.
# Source src = '/mysourcepath' # Destination dest = '/mydestinationpath' # Copy the content of src to dst try: shutil.copytree(src, dest, dirs_exist_ok=True) except OSError as err: # error caused if the source is not a directory if err.errno == errno.ENOTDIR: # create a new file with the good name in the destination folder f = open(dest, "x") else: print("Error: % s" % err)