Python Forum
How to copy files from subfolders into one folder
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to copy files from subfolders into one folder
#1
Hi Smile
I want to copy tif files contained in subfolders of folder "U:\\collections\\2019_input\\" in one separated output folder "U:\\collections\\2019_output\\" (no subfolders needed in the output).
My code :
input = "U:\\collections\\2019_input\\"
output = "U:\\collections\\2019_output\\"

for dirpath, dirnames, filenames in os.walk(input):
    for filename in filenames:
        if filename.endswith(".tif"):
            shutil.copy2(filename, output)
But it seems that shutil.copy2 command does not find the file to be copied.
Any idea?
Thanks !
Reply


Messages In This Thread
How to copy files from subfolders into one folder - by silfer - Aug-28-2019, 03:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 300 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Copy Paste excel files based on the first letters of the file name Viento 2 473 Feb-07-2024, 12:24 PM
Last Post: Viento
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 595 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Rename files in a folder named using windows explorer hitoxman 3 775 Aug-02-2023, 04:08 PM
Last Post: deanhystad
  Rename all files in a folder hitoxman 9 1,539 Jun-30-2023, 12:19 AM
Last Post: Pedroski55
  Create new folders and copy files cocobolli 3 1,522 Mar-22-2023, 10:23 AM
Last Post: Gribouillis
  Copy only hidden files and folders with rsync Cannondale 2 1,038 Mar-04-2023, 02:48 PM
Last Post: Cannondale
  How to loop through all excel files and sheets in folder jadelola 1 4,553 Dec-01-2022, 06:12 PM
Last Post: deanhystad
  python move folders and subfolders not working mg24 5 2,231 Nov-09-2022, 02:24 PM
Last Post: Larz60+
  python gzip all files from a folder mg24 3 4,097 Oct-28-2022, 03:59 PM
Last Post: mg24

Forum Jump:

User Panel Messages

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