无法获取 /path/ 的每个文件夹

Can't get every folder of /path/

我把代码写成

  set localaccount to {"1", "2"}
set locacc to choose from list localaccount with prompt "Select your Account Location:" default items {"1"}


set accounstlist to POSIX path of thisFolder & "accountlist.txt"
set folderloc to POSIX path of thisFolder & locacc
tell application "System Events"
    set applicationNames to name of folders of folderloc
end tell
set {TID, text item delimiters} to {text item delimiters, linefeed}
set namesText to applicationNames as text
set text item delimiters to TID
try
    set fileDescriptor to open for access accounstlist with write permission
    write namesText to fileDescriptor
    close access fileDescriptor
on error e number n
    try
        close access file accounstlist
    end try
    display dialog "Error: " & e & " - number: " & n buttons {"Cancel"} default button "Cancel"
end try
set theaccounts to paragraphs of (read accounstlist)
set theaccount to choose from list theaccounts with prompt "Select Account You Want To Export"

但是在 运行 它给了我无法获取 /path/ 的每个文件夹 路径是“folderloc” 谁能帮帮我?

我通过修改代码解决了这个问题:

set accounstlist1 to POSIX path of thisFolder & "accountlist.txt"
    set accounstlist1 to POSIX file accounstlist1
    set accounstlist to accounstlist1 as alias
    set folderloc1 to POSIX path of thisFolder & locacc
    set folderloc1 to POSIX file folderloc1
    set folderloc to folderloc1 as alias

问题出在路径上。 感谢大家的帮助。

自己解决的真好。几乎可以肯定问题出在 System Events 块中,您试图从该块中检索 folderloc 中的文件夹列表。在您的原始脚本中,folderloc 只是一个包含纯文本 posix 路径的字符串,因此当您要求 System Events 从中获取文件夹时,它没有任何意义一段文字。您的编辑通过将 posix 路径转换为 ​​POSIX file 然后转换为 alias 来解决此问题,然后 System Events 可以访问该路径以获取您的列表文件夹数量。

这是您的脚本的更正版本,其中删除了很多不必要的多余脂肪:

set localaccount to {"1", "2"}
set locacc to choose from list localaccount with prompt "Select your Account Location:" default items {"1"}
set accounstlist to POSIX path of thisFolder & "accountlist.txt"
set folderloc to POSIX path of thisFolder & locacc
set text item delimiters to linefeed
tell application "System Events" to set namesText to ¬
        (name of folders of folder folderloc) as text
write namesText to accounstlist
set theaccounts to paragraphs of (read accounstlist)
set theaccount to choose from list theaccounts with prompt "Select Account You Want To Export"