Python Forum
Python Cut/Copy paste file from folder to another folder - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python Cut/Copy paste file from folder to another folder (/thread-29126.html)



Python Cut/Copy paste file from folder to another folder - rdDrp - Aug-19-2020

I have bunch of PDFs that are reports generated by system named AR_00002755, AR_00002758, AR_00002760 ...so on etc.

I already have Folders named as 00002755, 00002758, 00002760 ...so on etc.

What i want to achieve is cut the PDF file "AR_00002755.pdf" and paste it inside Folder named "00002755"

My Folder at the moment looks like this:-

  1. Folder - 00002755
  2. Folder - 00002758
  3. Folder - 00002760
  4. AR_00002755.pdf
  5. AR_00002758.pdf
  6. AR_00002760.pdf


My end goal is, when I run the python script all the pdfs will go into their respective folders.


RE: Python Cut/Copy paste file from folder to another folder - ndc85430 - Aug-19-2020

Do you just mean that you want to move the files? Look at the shutil module.


RE: Python Cut/Copy paste file from folder to another folder - rdDrp - Aug-19-2020

(Aug-19-2020, 11:48 AM)ndc85430 Wrote: Do you just mean that you want to move the files? Look at the shutil module.

Yes i want to move pdf from the current folder to the 'named' folder, i.e. move "AR_00002755.pdf" to folder named "00002755"


RE: Python Cut/Copy paste file from folder to another folder - ndc85430 - Aug-19-2020

Then my advice still stands.


RE: Python Cut/Copy paste file from folder to another folder - rdDrp - Aug-19-2020

(Aug-19-2020, 12:01 PM)ndc85430 Wrote: Then my advice still stands.

I am reading shutil but i am unable to understand how to pick exactly the AR_00002755.pdf and put inside the folder named 00002755...

The only thing i got so far is i can move file 1,2,3, to another any folder but how exactly to folder named similar to PDF except few words either at beginning or at end??

In my case the words 'AR_' are present in PDFs but not in folder.