I have a script that I want to use in order to enumerate all file types in a folder:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import argparse
import magic
import os
# Argparse starts here
parser = argparse.ArgumentParser()
parser.add_argument('-input', dest='input',help="input one or more files",nargs='+',metavar=None)
args = parser.parse_args()
for files in args.input:
if magic.from_file(files,mime=True) == "text/plain":
print (files, "=" , magic.from_file(files,mime=True) )
it works pretty well when I input a file:
even when I input two files:
but not when I input ALL files:
The error says:
Traceback (most recent call last):
File "Test.py", line 15, in <module>
if magic.from_file(files,mime=True) == "text/plain":
File "C:\Users\FrancescoM\AppData\Local\Programs\Python\Python36-32\lib\site-packages\magic\magic.py", line 135, in from_file
return m.from_file(filename)
File "C:\Users\FrancescoM\AppData\Local\Programs\Python\Python36-32\lib\site-packages\magic\magic.py", line 85, in from_file
with open(filename):
OSError: [Errno 22] Invalid argument: '*.txt'
But *.txt
is exactly what I want to input; I also would like to input whatever file *.*
Is this a problem related to python-magic
or caused by the way I input the files?