I have a script where I want to get the name of each file along the first line inside each file and pass those files to a list within a txt.
#modifica titulos de arquivos
import os
import glob
s=("-")
arq=open("listapdf.txt","w")
for file in glob.glob('*.pdf'):
f = str(file.name)
fr = str(file.readline())
arq.write(f+s+fr)
arq.write("\n")
exception (RuntimeError, TypeError, NameError)
pass
in the output points the following error:
h1k3rpath@h1k3rpath-Ubuntu:~/Downloads/recovery/sabadoroadsec/pdf$
python3 lista.py Traceback (most recent call last): File "lista.py",
line 9, in <module>
f = str(file.name) AttributeError: 'str' object has no attribute 'name'
I have already changed and refactored the call with str
and no str
I tried to use the keyword instead of naming variant, tried some other things, but I still can not get around this error.
I'm not correctly using file.name
or have another way of doing this?