Python Forum

Full Version: Python Cut/Copy paste file from folder to another folder
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
Do you just mean that you want to move the files? Look at the shutil module.
(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"
Then my advice still stands.
(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.