【发布时间】:2019-11-24 12:05:52
【问题描述】:
我正在寻找对当前脚本的编辑。我需要将所有文件从子文件夹(递归)移动到一个顶级文件夹,但是如果存在同名文件,请创建一个新的顶级文件夹并继续在那里,这就是我目前所拥有的:
tell application "Finder"
try
set Random_name to random number from 100 to 9999
set theTopFolder to (choose folder)
set theFiles to a reference to every file of (entire contents of folder theTopFolder)
set theNewFolder to make new folder at theTopFolder with properties {name:"Flattened Files"}
move theFiles to theNewFolder
on error
set theNewFolder to make new folder at theTopFolder with properties {name:"Flattened Files" & Random_name}
move theFiles to theNewFolder
end try
end tell
只是要明确路径的结构不是:
Mainfolder/subfolder/file.xxx 但 Mainfolder/subfolder/sulbfolder2/subfolder3/....100/file.xxx 所以脚本需要递归地工作,但它会在存在同名文件时停止
当存在同名文件时,我的编辑会创建一个新文件夹,其中包含扁平文件+随机数,但是当移动另一个同名文件时,脚本会因错误而停止,而是继续创建新的扁平文件+随机数文件夹。有什么想法吗?
谢谢
【问题讨论】:
-
所以您想为重复名称创建一个新文件夹,而不是仅仅添加一个后缀?如果你有多个同名的文件或顶级文件夹,你想怎么办?
-
嘿@red_menace 感谢您的回复。我正在寻找的是文件夹 Flattened Files1、Flattened Files2、Flattened Files3 等等,包含子文件夹的所有文件。当然,如果没有重复,Flattened Files1 应该包含所有文件。是的,重要的是不要触及文件的名称
标签: applescript