0

I was wondering if there was a way to do this in Python:

  • From a directory, select multiple specific files (e.g. .JPG and .PNG), copy the files and paste it into another application.

I know that if we are just moving the files to another directory we can do something like:

for files in glob.glob(r'*PNG'):
        shutil.copy(files, dir) 

But this won't allow me to copy to the clipboard so I can just paste the files. I've tried looking at pyperclip but that would only allow for strings.

So basically what I tried is Ctrl + A, Ctrl + C and pasting it (using pynput.keyboard) into an application. However this method, doesn't allow me to copy only specific files.

Dave White
  • 31
  • 3
  • Looks like a duplicate post. You should take a look at this post https://stackoverflow.com/questions/123198/how-do-i-copy-a-file-in-python?rq=1 – SaaSy Monster Sep 09 '20 at 05:58
  • I've went through them, but the options don't allow for the files to be copied into a clipboard (like how Ctrl+C and Ctrl+V does), right? – Dave White Sep 09 '20 at 06:27

1 Answers1

0

See if this helps. This will copy all the png files from the source path and paste them in the destination path. For this we need to use a combination of packages. OS, glob, shutil.

source = "dir/path"
destination = "dir/path"

# This will target the PNG files
for images in glob.iglob(os.path.join(source, "*.png")):
    shutil.copy(images, destination)

# This will target the JPG files   
for images in glob.iglob(os.path.join(source, "*.jpg")):
    shutil.copy(images, destination)
SaaSy Monster
  • 552
  • 2
  • 16