Definitely a more verbose option (python) that looks for mimetype(s) using the file
command. It is an edited/rewritten version of this one, made fit for your purpose.
What it does
When files are found
it returns a message (in the terminal):
checking for filetypes: image, video, audio...
4 media files found. See for details: /home/jacob/Bureaublad/found.txt
while a text file is written to the directory/name you defined in the head section of the script
or, if nothing is found:
checking for filetypes: image, video, audio...
no files found
How to use
Copy the script below into an empty file, edit the three lines in the head section of the script:
source_dir = "/path/to/directory"
filetypes = ("image", "video", "audio") # you might want to leave this line as it is, used by the file command
report = "/path/to/report.txt"
save it as find_media.py
, and run it in a terminal window by the command:
python3 /path/to/find_media.py
The script:
#!/usr/bin/env python3
import os
import subprocess
# ---
source_dir = "/path/to/directory"
filetypes = ("image", "video", "audio")
report = "/path/to/report.txt"
# ---
print("checking for filetypes: "+(", ").join(filetypes)+"."*3)
found = []
def look_for():
for root, dirs, files in os.walk(source_dir):
for name in files:
file = root+"/"+name
ftype = subprocess.check_output(
['file', '--mime-type', '-b', file]
).decode('utf-8').strip()
if ftype.split("/")[0] in filetypes:
found.append(file)
found_files = len(found)
if found_files != 0:
print(str(found_files), "media files found. See for details: ", report)
with open(report, "wt") as out:
for item in found:
out.write(item+"\n")
else:
print("no files found")
look_for()
find /home -type f -regextype posix-extended -iregex '.*(mp3|wma|mpg|mov)$'
. That ought to get you started. Combine withwc -l
to see the number of files.