Windows Powershell에서 pdfminer에서 스크립트를 실행하는 루프를 실행 중입니다. 파일 디렉터리에서 pdf2txt.py를 실행합니다. 루프가 있습니다 :IOError : Errno 13 Permission Denied D : Powershell에서 python 루프를 실행할 때/PDFs
$PATH="D:/PDFdirectory"
foreach ($f in $PATH)
{
python pdf2txt.py -o $f.txt "$f" "${f%.pdf}.txt"
}
Powershell에서 위의 코드를 실행하려고하면 권한이 거부되었습니다. 오류가 발생합니다. 오류는 아래의 pdf2txt 스크립트에서 outfp = file (outfile, 'w + b')을 가리 킵니다.
if outfile:
outfp = file(outfile, 'w+b')
else:
outfp = sys.stdout
if outtype == 'text':
device = TextConverter(rsrcmgr, outfp, codec=codec, laparams=laparams,
imagewriter=imagewriter)
elif outtype == 'xml':
device = XMLConverter(rsrcmgr, outfp, codec=codec, laparams=laparams,
imagewriter=imagewriter)
elif outtype == 'html':
device = HTMLConverter(rsrcmgr, outfp, codec=codec, scale=scale,
layoutmode=layoutmode, laparams=laparams,
imagewriter=imagewriter)
elif outtype == 'tag':
device = TagExtractor(rsrcmgr, outfp, codec=codec)
else:
return usage()
for fname in args:
fp = file(fname, 'rb')
interpreter = PDFPageInterpreter(rsrcmgr, device)
for page in PDFPage.get_pages(fp, pagenos,
maxpages=maxpages, password=password,
caching=caching, check_extractable=True):
page.rotate = (page.rotate+rotation) % 360
interpreter.process_page(page)
fp.close()
device.close()
outfp.close()
return
if __name__ == '__main__': sys.exit(main(sys.argv))
pdf2txt.py의 읽기 및 쓰기 조건을 Windows와 호환되도록 바이너리로 변경했지만 지금은 붙어 있습니다. 아무도 나를 도울 수 있습니까?
감사합니다.
Powershell을 관리자로 실행하고 있습니까? –
예 관리자로 시작했습니다 – ChuckD
'foreach ($ f in $ PATH)'로 원하는 것을 할 수 있습니까? 정확히 하나의 항목, 즉 디렉토리 이름이있는 것처럼 보이며 해당 디렉토리에있는 파일을 열거하지 않습니다. – dpw