Applescript 是否正在处理脚本运行时创建的新文件夹? [英] Is Applescript processing new folders that are created in the moment the script runs?

查看:21
本文介绍了Applescript 是否正在处理脚本运行时创建的新文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本,该脚本将文件夹从 afp 共享复制到本地文件夹,然后对这些文件夹执行各种操作.(复制后删除原来的文件夹)

I am working on a script that duplicates folders from an afp share to a local folder and does all kind of things with those folders afterwards. (it deletes the original folders after duplicating)

此代码运行良好:

tell application "Finder"
duplicate every folder of folder afpFolder to localFolder with replacing
delete every folder of folder afpFolder
end tell

我的问题是我们的员工会定期且经常向 afpFolder 添加新文件夹.我的脚本每 10 秒运行一次(使用 LaunchAgents),因为它需要尽可能频繁地处理重复数据.

My problem is that our employees will be adding new folders to afpFolder regulary and quite often. My script is running every 10 seconds (with LaunchAgents) because it needs to process the duplicated data as often as possible.

我的问题是:当脚本复制和删除文件夹并且在确切同一时刻有人向afpFolder添加一个新文件夹时会发生什么?

The question I have is: What happens when the script is duplicating and deleting folders and in the exact same moment somebody adds a new folder to afpFolder?

脚本是否只删除 afpFolder 开始运行时中的内容,或者它会删除那些新创建的文件夹之一而不复制它?

Does the script only delete what was in afpFolder in the moment it started running or could it be that it would delete one of those newly created folders without duplicating it?

我也想过用列表做点什么.例如:

I have also thought about making something with a list. For example:

set folderList to {}
tell application "Finder" to set folderList to every folder of afpFolder
duplicate folderList to localFolder
delete folderList

(这种方式可能行不通)

(this might not work this way)

谁能帮我回答这个问题?

Can anyone please help me answer the question?

我可以使用我只是复制和删除的上层代码吗?或者我是否必须担心脚本会删除在脚本运行时创建的文件夹而不复制它们?

Can I work with the upper code where I just duplicate and delete? Or do I have to worry about the script deleting folders that are created in the moment the script runs, without duplicating them?

如果上面的代码会引起麻烦,你能帮我解决列表吗?

If the upper code can cause trouble, can you help me with the list solution?

推荐答案

第一个脚本将删除在重复和删除命令之间添加的项目.但我想不出第二种方法行不通的任何情况:

The first script would delete items that are added between the duplicate and delete commands. But I can't think of any case where the second approach would not work:

tell application "Finder"
    set l to items of ((POSIX file "/private/tmp/test") as alias)
    duplicate l to desktop
    delete l
end tell

您也可以尝试使用 mv 或 rsync:

You could also try using mv or rsync:

do shell script "mv /path/to/afp_folder/* /path/to/local_folder/"
do shell script "rsync -a /path/to/afp_folder/ /path/to/local_folder/
rm -r /path/to/afp_folder/*"

这篇关于Applescript 是否正在处理脚本运行时创建的新文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆