Python Forum
Move Files based on partial Match
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Move Files based on partial Match
#3
Use Code tags.
Your description most have been basic and leaving out the 5000 part.
An other problem if don't know Python,then it can be hard to fix or suggest a update from ChatGPT.

Something like this and using pathlib
from pathlib import Path
import shutil

dir_find = '5000'
source_folder = Path("G:/div_code/Source")
des_folder = Path("G:/div_code")
des_subfolder = des_folder / dir_find
for file in source_folder.glob(f"{dir_find}*"):
    # Create the des subfolder if it doesn't exist
    des_subfolder.mkdir(parents=True, exist_ok=True)
    des_file = des_subfolder / file.name
    # move file can also use .copy
    shutil.move(file, des_file)
Reply


Messages In This Thread
RE: Move Files based on partial Match - by snippsat - Sep-20-2023, 07:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy Paste excel files based on the first letters of the file name Viento 2 492 Feb-07-2024, 12:24 PM
Last Post: Viento
  partial functions before knowing the values mikisDeWitte 4 663 Dec-24-2023, 10:00 AM
Last Post: perfringo
  Making a question answering chatbot based on the files I upload into python. Joejones 1 1,296 May-19-2023, 03:09 PM
Last Post: deanhystad
  Partial KEY search in dict klatlap 6 1,329 Mar-28-2023, 07:24 AM
Last Post: buran
  python move specific files from source to destination including duplicates mg24 3 1,138 Jan-21-2023, 04:21 AM
Last Post: deanhystad
  remove partial duplicates from csv ledgreve 0 824 Dec-12-2022, 04:21 PM
Last Post: ledgreve
  Webhook, post_data, GPIO partial changes DigitalID 2 1,028 Nov-10-2022, 09:50 PM
Last Post: deanhystad
  Optimal way to search partial correspondence in a large dict genny92c 0 1,019 Apr-22-2022, 10:20 AM
Last Post: genny92c
  select Eof extension files based on text list of filenames with if condition RolanRoll 1 1,557 Apr-04-2022, 09:29 PM
Last Post: Larz60+
  Rename Files based on XML file klturi421 3 2,241 Oct-22-2021, 07:37 PM
Last Post: klturi421

Forum Jump:

User Panel Messages

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