Automatically Detecting Image And Video Files For Further Processing
So I want to write a script which I only give a path to either a folder or a file, and it will then detect all video and image files and put them in a list of videos and a list of
Solution 1:
There is a library available just for this purpose. It surely will simplify the task.
Install the library filetype from HERE which can be easily installed using pip
. The list of supported file types are also mentioned.
import filetype
file = filetype.guess(r'C:\Users\Jackson\Desktop\car.png')
if file is None:
print('Cannot guess file type!')
elif:
print('File extension: %s' % file.extension)
print('File MIME type: %s' % file.mime)
I passed in a .png
file which resulted in:
File extension: png
File MIME type: image/png
Using the mime
attribute you can determine what type your file is.
Post a Comment for "Automatically Detecting Image And Video Files For Further Processing"