我试图找到要添加CopyRigth块的文件。 所以,我写这个:
import os
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith(".cs"):
try:
content = open(root + "\\" + file, "rt", encoding="utf-8").readlines()[0]
if not content.startswith("#region Copy"):
print(content)
print(content.startswith("#region Copy"))
print(root + "\\" + file)
except Exception as e:
pass
可以使用,但如果注释print(content)
,则会打印所有文件名
import os
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith(".cs"):
try:
content = open(root + "\\" + file, "rt", encoding="utf-8").readlines()[0]
if not content.startswith("#region Copy"):
# print(content)
print(content.startswith("#region Copy"))
print(root + "\\" + file)
except Exception as e:
pass
有这种魔力的原因吗?