Mehdi
Mehdi

Reputation: 1296

Copy files out of nested subdirectories into another folder

I have a parent directory (call it Parent) which includes nested subdirectories. I want to copy jpeg files in nested subdirectories to another directory (call it NEW). How can I do that?

Upvotes: 0

Views: 98

Answers (2)

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

find + cp solution:

find Parent -type f -name"*.jpeg" -exec cp -t NEW {} +

Upvotes: 1

DamienzOnly
DamienzOnly

Reputation: 88

create a new python script with the following code:

import glob
import shutil
import os

src_dir = "your/source/dir"
dst_dir = "your/destination/dir"
for jpgfile in glob.iglob(os.path.join(src_dir, "*.jpg")):
    shutil.copy(jpgfile, dst_dir)

the save it "filename.py" and in terminal run "python filename.py"

Upvotes: 1

Related Questions