【发布时间】:2016-09-06 01:54:13
【问题描述】:
我有一个由另一个用户在这里慷慨创建的脚本,但我发现它不会递归地读取目录。该脚本的目标是读取在 Finder 中选择的目录的所有子目录,并写出 255 个字符或更长的文件的任何绝对路径(路径不是文件名)。这是为了查找绝对路径长度在 OSX 上对于具有 255 个字符路径限制的 Windows 机器来说太长的文件,然后再将它们从一个文件传输到另一个文件。
我尝试引用这篇文章以使其递归但无济于事,因为这里的方法看起来完全不同:AppleScript Processing Files in Folders recursively
on run
set longPaths to {}
tell application "Finder" to set theSel to selection
repeat with aFile in theSel
set aFile to aFile as string
set pathLength to count of characters in aFile
if pathLength > 255 then
set end of longPaths to aFile
end if
end repeat
if longPaths is not equal to {} then
-- do something with your list of long paths, write them to a text file or whatever you want
set pathToYourTextFile to (path to desktop folder as string)&"SampleTextFile.txt"
set tFile to open for access file (pathToYourTextFile as string) with write permission
repeat with filePath in longPaths
write (filePath & return as string) to tFile starting at eof
end repeat
close access tFile
end if
end run
有谁知道向该脚本添加递归元素的最佳方法,以便 theSel 包含所选目录的子目录中的所有文件?
【问题讨论】:
-
你现在得到的结果是什么?请在您的问题中添加一个示例。
-
目前,该脚本只会读取 Finder 中突出显示的文件或文件夹。如果文件或目录的绝对路径超过 255 个字符,它会将该路径写入桌面上名为“SmpleTextFile.txt”的文本文件。所以问题在于“将 theSel 设置为选择”只是在 Finder 中突出显示的那些项目,而我正在寻找一种方法让选择包括所选目录(包括子目录)中的所有文件。
-
检查我在“列出绝对路径...”问题中的答案。
标签: macos recursion applescript