2013-11-04 37 views
0

我想做一个循环脚本,将父文件夹,并找到所有的子文件夹。这样,我可以一次拿一个,然后在其上运行第二个脚本。查找和列出所有子文件夹,但没有别的

这将工作,如果我在寻找文本文件。我想尝试使用它来查找文件夹,但不知道如何在该方向上找不到任何内容。

-- Search for Subfolder 
set ParentPath to choose folder 
set allFiles to (do shell script "find " & quoted form of POSIX path of ParentPath & " -iname \"*.eps\"")) 


-- Process files 
repeat with nFile in allFiles 
    my runScript(nFile) 
end repeat 

理论上会是这样。

-- Search for Subfolder 
set ParentPath to choose folder 
set allFiles to all folders inside ParentPath 


-- Process files 
repeat with nFile in allFiles 
    my runScript(nFile) 
end repeat 

谢谢!

回答

0

发现这个完美的作品。

set ParentPath to (choose folder) as string 
set FolderList to {} 
tell application "System Events" 
    set ItemList to disk items of folder ParentPath 
    repeat with CurrentItem in ItemList 
     if (class of CurrentItem) = folder then 
      set end of FolderList to ((path of CurrentItem) as alias) 
     end if 
    end repeat 
end tell 
0

使用bash,你会说:

shopt -s globstar nullglob 
# the trailing slash below restricts matches to directories. 
for dir in **/; do 
    some command with "$dir" 
done 

这递归地查找当前目录下的所有目录。如果你只是寻找当前目录的子目录中:for dir in */

0
find <dirname> -type d > subdirlist 

你并不需要指定查找深度级别,要么;它会一直持续下去。如果你不想太过分,你只能指定一个最大深度。

您也可以使用find循环作为处理脚本的基础。举一个例子: -

find *.mp3 d.mp3 -type f | while read mp3s 
do 
echo $mp3s 
<more commands> 
done 
0

刚刚尝试下面:

find ./ -type d 
+0

我在applescript写这个。这将如何被格式化成一个do shell脚本? –

+0

@Tim Joe所以你的意思是你想通过applescript实现这个? – Nancy

+0

正确。没有formillar,但我知道这将是一个do shell脚本(“find”./ -type d) –

相关问题