删除子文件夹中的所有内容
Delete everything from subfolders
下面是我的脚本(不要问我是怎么弄到这个的)。
我知道这是愚蠢和沉重的。
我只需要最简单的脚本即可转到子文件夹并删除:
- 变体。一切都来自于它。
- 变体。 .mp4 文件
不删除子文件夹。
感谢您的帮助。
property source_folder : alias "Macintosh HD:Users:User:Pictures:4K Stogram:"
property save_folder : path to trash folder as string
# set source_folder to choose folder with prompt "Select the folder of folders containing images."
# set save_folder to choose folder with prompt "Select the folder to save the images in."
process_folder(source_folder)
on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
set container_name to name of (info for this_folder)
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
if folder of (info for this_item) is true then
process_folder(this_item)
else
process_item(this_item, container_name, i)
end if
end repeat
end process_folder
-- this sub-routine processes files
on process_item(this_item, c, i)
tell application "System Events"
move this_item to save_folder
end tell
end process_item
使用函数"entire contents"获取所有文件,包括递归子文件夹内容。下面的 6 行脚本将替换您的完整脚本。
set SourceFolder to choose folder with prompt "Source folder"
set SaveFolder to choose folder with prompt "Save folder"
tell application "Finder"
set myFiles to every file of entire contents of SourceFolder
move myFiles to SaveFolder
end tell
您还可以通过 "mp4" 等扩展名过滤所选文件,方法是在第 4 行添加过滤器。您甚至可以设置扩展名列表!
set myFiles to every file of entire contents of SourceFolder whose name extension is "mp4"
要递归删除给定文件夹的所有子文件夹中的每个文件但保持文件夹结构,shell 命令 find
非常合适,因为它比 Finder 快得多。
- 如果 属性
deleteOnlyMP4
设置为 true
只有扩展名为 mp4
的文件将被移动到回收站文件夹。
如果 属性 deleteOnlyMP4
设置为 false
所有文件都将移至回收站文件夹。
property deleteOnlyMP4 : true
set source_folder to POSIX path of (path to pictures folder) & "4K Stogram"
if deleteOnlyMP4 then
do shell script "/usr/bin/find " & quoted form of source_folder & " -iname '*.mp4' -exec /bin/mv {} ~/.Trash \;"
else
do shell script "/usr/bin/find " & quoted form of source_folder & " -type f -exec /bin/mv {} ~/.Trash \;"
end if
下面是我的脚本(不要问我是怎么弄到这个的)。 我知道这是愚蠢和沉重的。 我只需要最简单的脚本即可转到子文件夹并删除:
- 变体。一切都来自于它。
- 变体。 .mp4 文件
不删除子文件夹。
感谢您的帮助。
property source_folder : alias "Macintosh HD:Users:User:Pictures:4K Stogram:"
property save_folder : path to trash folder as string
# set source_folder to choose folder with prompt "Select the folder of folders containing images."
# set save_folder to choose folder with prompt "Select the folder to save the images in."
process_folder(source_folder)
on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
set container_name to name of (info for this_folder)
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
if folder of (info for this_item) is true then
process_folder(this_item)
else
process_item(this_item, container_name, i)
end if
end repeat
end process_folder
-- this sub-routine processes files
on process_item(this_item, c, i)
tell application "System Events"
move this_item to save_folder
end tell
end process_item
使用函数"entire contents"获取所有文件,包括递归子文件夹内容。下面的 6 行脚本将替换您的完整脚本。
set SourceFolder to choose folder with prompt "Source folder"
set SaveFolder to choose folder with prompt "Save folder"
tell application "Finder"
set myFiles to every file of entire contents of SourceFolder
move myFiles to SaveFolder
end tell
您还可以通过 "mp4" 等扩展名过滤所选文件,方法是在第 4 行添加过滤器。您甚至可以设置扩展名列表!
set myFiles to every file of entire contents of SourceFolder whose name extension is "mp4"
要递归删除给定文件夹的所有子文件夹中的每个文件但保持文件夹结构,shell 命令 find
非常合适,因为它比 Finder 快得多。
- 如果 属性
deleteOnlyMP4
设置为true
只有扩展名为mp4
的文件将被移动到回收站文件夹。 如果 属性
deleteOnlyMP4
设置为false
所有文件都将移至回收站文件夹。property deleteOnlyMP4 : true set source_folder to POSIX path of (path to pictures folder) & "4K Stogram" if deleteOnlyMP4 then do shell script "/usr/bin/find " & quoted form of source_folder & " -iname '*.mp4' -exec /bin/mv {} ~/.Trash \;" else do shell script "/usr/bin/find " & quoted form of source_folder & " -type f -exec /bin/mv {} ~/.Trash \;" end if