我想将大量的html文件转换为txt文件。我已经从github下载了inscript命令行工具,但是我正在努力将其应用到位于子目录中的所有html文件,然后将这些文件另存为文本文件,放置在html文件所在的同一目录中。
我尝试过:
for f in ./ do inscript.py -o test.txt done
以下应该起作用:
for d in ./**/*/; do
pushd "$d"
for f in ./*.html; do
out=test-${f%.html}.txt
inscript.py -o "$out" "$f"
done
popd
done
模式.**/*
/will recursively match the current directory and all its subdirectories.
pushdwill change to a directory, but remember the current working directory.
inscript.pydoes its thing, then
popdreturns to the original working directory so that the next value of
d`仍然有效相对目录。
更改工作目录不是绝对必要的;它只是简化了所涉及的文件路径,因为您专注于文件名而忽略了其余路径。