Software Engineering

Transfer Recordsdata From One Listing to One other Utilizing Python

Transfer Recordsdata From One Listing to One other Utilizing Python
Written by admin


If it’s essential to transfer information from one listing to a different listing, utilizing Python, then you are able to do one of many following:

Choice 1 – Utilizing shutil.transfer()

import shutil
import os
 
file_source = 'supply/listing'
file_destination = 'vacation spot/listing'
 
get_files = os.listdir(file_source)
 
for file in get_files:
    shutil.transfer(file_source + file, file_destination)

Choice 2 – Utilizing os.substitute()

import os
 
file_source = 'supply/listing'
file_destination = 'vacation spot/listing'
 
get_files = os.listdir(file_source)
 
for file in get_files:
    os.substitute(file_source + file, file_destination + file)

Choice 3 – Utilizing pathlib

from pathlib import Path
import shutil
import os

file_source ='supply/listing'
file_destination ='vacation spot/listing'

for file in Path(file_source).glob('some_file.txt'):
    shutil.transfer(os.path.be part of(file_source,file), file_destination)

About the author

admin

Leave a Comment