Python Forum
python move specific files from source to destination including duplicates
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python move specific files from source to destination including duplicates
#1
Hi Team,

I have 2000 csv files in a source folder. airtel,jio data files etc.
file naming convention start with mobile no and then string value concatenation.

I have list of 800 mobile phones , I have to search source folder if file contains any of these mobile no,

I want to move all files including duplicate files also.

below is attempted code , which is working , it should move duplicate files as well.
but its moving single file only.


import glob
import os
import shutil
import csv

SOURCE_PATH = r"E:\data\src"
TARGET_PATH = r"E:\data\destination"

with open(r'E:\data\mobile_list.csv','r') as f:
    reader = csv.reader(f)
    header = next(reader)
    for m in reader:
            for file in glob.glob(os.path.join(SOURCE_PATH, f'*{m}*')):                
                shutil.move(file, TARGET_PATH)                
                print("success")
Reply


Messages In This Thread
python move specific files from source to destination including duplicates - by mg24 - Jan-20-2023, 07:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Algorithm for extracting comments from Python source code Pavel1982 6 542 Feb-28-2024, 09:52 PM
Last Post: Pavel1982
  Move Files based on partial Match mohamedsalih12 2 834 Sep-20-2023, 07:38 PM
Last Post: snippsat
  Function to count words in a list up to and including Sam Oldman45 15 6,618 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  mouse move event/cinfiguration ttk/python janeik 4 1,077 Jul-03-2023, 05:30 PM
Last Post: deanhystad
  python print all files which contain specific word in it mg24 5 1,261 Jan-27-2023, 11:20 AM
Last Post: snippsat
  remove partial duplicates from csv ledgreve 0 797 Dec-12-2022, 04:21 PM
Last Post: ledgreve
  python move folders and subfolders not working mg24 5 2,193 Nov-09-2022, 02:24 PM
Last Post: Larz60+
  Python Snippets Source kucingkembar 0 644 Oct-18-2022, 12:50 AM
Last Post: kucingkembar
  Long-term stable source to get news headlines with Python? sandufi 4 1,944 Dec-23-2021, 09:48 AM
Last Post: sandufi
  Problem : Count the number of Duplicates NeedHelpPython 3 4,394 Dec-16-2021, 06:53 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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