How to move all only one type of file to another directory? For example, i want to move only all .jpg only file to another folder in Python. I know batch is easier to do it, but i prefer in Python. Anyone can help?
I would use os.listdir, and shutil.move (or copy). Here's a useful function to sort by extension:
"""Returns all files of type ext in filelist"""
returnfiles = 
for item in filelist:
x = item.split(".")
#Take all files of THIS type
if str(x) == ext:
So this is what it would look like:
for jpg in filterbyext(os.listdir(os.getcwd()),'jpg'):