我一直试图找到解释如何读取AppleScript中多个文件的内容,但我只能找到读取1个文件的内容。
e.g。
谢谢!
答案 0 :(得分:0)
set output to ""
tell application "Finder"
repeat with f in (get files of (get POSIX file "/Users/username/Folder" as alias))
if (read (f as alias) as «class utf8») contains "© 2013 copyright" then
set output to output & name of f & " - PASS" & linefeed
else
set output to output & name of f & " - FAIL" & linefeed
end if
end repeat
end tell
set b to open for access "/Users/username/Desktop/output.txt" with write permission
set eof b to 0
write output to b as «class utf8»
close access b
如果省略as «class utf8»
,则read
和write
会使用主要编码,例如MacRoman或MacJapanese。 Unicode text
是UTF-16。
或者使用shell脚本:
for f in ~/Folder/*; do grep -q '© 2013 copyright' "$f" && x=PASS || x=FAIL; echo "${f##*/} - $x"; done > ~/Desktop/output.txt
grep -lv '© 2013 copyright' ~/Folder/*