以下是可能的解决方法之一,这个脚本可以检查文件夹中是否有与HTML文件同名的对应文件,如果存在,向HTML文件添加注释标签,如果不存在,删除注释标签。该脚本可以在命令行中执行。将以下脚本保存为一个.sh文件并使其可执行,然后在终端中运行脚本文件即可。
#!/bin/bash
#Enter the name of the directory in which the files are present
#输入包含文件的目录名称
directory_name="my_folder"
#Iterate through all the HTML files in the directory
#遍历目录中的所有HTML文件
for file in "$(find $directory_name -name '*.html')"
do
#Get the corresponding file name
#获取与HTML文件同名的对应文件名
file_name=$(basename "${file%.*}")
corresponding_file="$directory_name/$file_name.txt"
#Check if corresponding file exists
#检查对应文件是否存在
if [ -e "$corresponding_file" ]
then
#Add comment tags to HTML file
#向HTML文件添加注释标签
sed -i '1i ' >> "$file"
else
#Remove comment tags from HTML file
#从HTML文件中删除注释标签
sed -i '//d' "$file"
fi
done
要运行该脚本,请打开终端并导航到包含脚本文件的目录。然后,输入以下命令运行该脚本:
./script_name.sh
请替换“script_name.sh”为你的脚本文件名。