0

I'm pretty new to python. I want to write a script that can move files from src folder to dest folder. And if the files are already existed in the dest folder, the files still move from src to dest and override the existing files. The only thing I can think of right now is to check the dest folder for existing files, and if there is, then that file will be removed before moving files from src to dest. Here is what I have so far

src_file=os.listdir(src)

for f in src_file: 
    fullname=os.path.join(dest,f)   
    if os.path.exists(fullname):
        os.remove(fullname)
        shutil.move(src,dest)

The problem I have with this script is that the files from src will be moved to a folder in the src and the src folder will be deleted. Is there a better way to do this?

EDIT: I have lots of data (milions of files) streaming to my src folder. So I will need to move files from src to dest. shutil.copy will not work in my case because I will end up to have a big size folder Thanks

VuNguyen
  • 1
  • 1
  • Just use `shutil.copy(src,dest)` – Axe319 Jan 09 '20 at 14:44
  • shutil.copy would not be very good solution for me as I have millions of files streaming to my src folder. So I would like to move files out of src folder to reduce the size. – VuNguyen Jan 09 '20 at 14:51
  • 1
    Does this answer your question? [Move and replace if same file name already existed in python](https://stackoverflow.com/questions/31813504/move-and-replace-if-same-file-name-already-existed-in-python) – Raphael Jan 09 '20 at 15:46

0 Answers0