对子文件夹中的所有html文件进行迭代运行脚本脚本工具

问题描述 投票:0回答:1

我想将大量的html文件转换为txt文件。我已经从github下载了inscript命令行工具,但是我正在努力将其应用到位于子目录中的所有html文件,然后将这些文件另存为文本文件,放置在html文件所在的同一目录中。

我尝试过:

for f in ./ do inscript.py -o test.txt done

loops zsh subdirectory
1个回答
0
投票

以下应该起作用:

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, thenpopdreturns to the original working directory so that the next value ofd`仍然有效相对目录。

更改工作目录不是绝对必要的;它只是简化了所涉及的文件路径,因为您专注于文件名而忽略了其余路径。

© www.soinside.com 2019 - 2024. All rights reserved.