我正在使用文件夹操作创建“热”文件夹,该文件夹立即将放置在此文件夹中的文件复制到特定的备份文件夹。
这是我用作文件夹操作的脚本,它可以正常工作:
int required_fs;
int des;
int idpk;
double holding;
int src;
//get the information about the packet that is sent from source to destination.
Packet *pkptr;
pkptr = op_pk_get (0);
op_pk_nfd_get(pkptr,"bw_fs",&required_fs);
op_pk_nfd_get(pkptr,"des",&des);
op_pk_nfd_get(pkptr,"src",&src);
op_pk_nfd_get(pkptr,"id",&idpk);
op_pk_nfd_get(pkptr,"ht",&holding);
bw_req=bw_req + required_fs;
number_of_req=number_of_req+1;
if (number_of_req > 1000000)
{
FILE* file1=fopen("C:/400f_rsa.txt","a+");
fprintf(file1,"\n");
fprintf(file1,"number_of_req ,number_of_nack,number_of_ack , bw_req , bw_nack , bw_ack " );
fprintf(file1,"\n");
fprintf(file1," %d , %d , %d , %d , %d , %d ", number_of_req, number_of_nack ,number_of_ack,bw_req,bw_nack,bw_ack );
fprintf(file1,"\n");
fprintf(file1,"------------------------------- ");
fclose (file1);
op_sim_end("1000000 paket","","","");
}
// Allocate the resources on each link to the working path, This part must be the same for the protection path too.
int determined_t=0;
int determined_r=0;
int determined_p_f=0;
int determined_p_e=0;
int determined_k=0;
for ( int i=1; i<=10; i++)
{
if (transmitter[src][i]==0)
{
determined_t=i;
break;
}
}
if (determined_t!=0)
{
for ( int i=1; i<=10; i++)
{
if (reciever[des][i]==0)
{
determined_r=i;
break;
}
}
if (determined_r!=0)
{
for ( int k=1; k<=2 ; k++)
{
determined_p_f=0;
determined_p_e=0;
int count = paths_node[src][des][k][2][14];
zero_array();
for (int i=1; i<=count; i++)
{
finding_fs( k, i, des, src );
}
if ( ff_rr==0)
{//ff
////checking gap
determined_p_f=find_first_free_gap(required_fs);
if (determined_p_f!=0)
{
determined_p_e=determined_p_f+required_fs-1;
if (determined_p_e != 1000)
{
determined_p_e=determined_p_e+1;
}
determined_k=k;
break;
}
}
else if (ff_rr==1)
{//rr
clear_rr_gap();
find_rr_gap(required_fs);
int index=rr_spectrum();
determined_p_f=ary_rr[index].first;
if (determined_p_f!=0)
{
determined_p_e=ary_rr[index].last;
determined_k=k;
break;
}
}
}
if (determined_p_f!=0)
{
//add to ls , applying
int count_link = paths_node[src][des][determined_k][2][14];
for ( int i=1; i<=count_link ; i++)
{
int num_link_p=paths_node[src][des][determined_k][2][i];
for ( int j=determined_p_f ; j<=determined_p_e; j++)
{
links_fs[num_link_p][j]=1;
}
}
reciever[des][determined_r]=1;
transmitter[src][determined_t]=1;
ls(determined_p_f,determined_p_e,determined_r,determined_t,determined_k,src,des,idpk);
number_of_ack= number_of_ack +1 ;
bw_ack= bw_ack + required_fs;
op_intrpt_schedule_self(op_sim_time ()+ holding,idpk);
op_pk_destroy(pkptr);
}
else
{
number_of_nack=number_of_nack+1;
bw_nack= bw_nack + required_fs;
op_pk_destroy(pkptr);
}
}
else
{
number_of_nack=number_of_nack+1;
bw_nack= bw_nack + required_fs;
op_pk_destroy(pkptr);
}
}
else
{
number_of_nack=number_of_nack+1;
bw_nack= bw_nack + required_fs;
op_pk_destroy(pkptr);
}
但是我想像普通的applescript一样运行此文件夹操作,并使用“选择文件夹”命令触发“添加文件夹项目”功能。因此,我可以手动指向特定的源文件夹和目标文件夹并运行脚本。
我尝试过,但是没有结果:
on adding folder items to this_folder after receiving these_items
tell application "Finder" to duplicate these_items to folder
("Macintosh HD:Users:photograper:Desktop:Target:")
end adding folder items to
任何建议如何将脚本的两个部分结合在一起以便它们可以交互?
答案 0 :(得分:0)
只需删除处理程序并为“ this_folder”更改变量“ these_items”,就像这样:
set this_folder to choose folder with prompt "Select source folder:" with multiple selections allowed
set target_folder to choose folder with prompt "Select backup folder:"
tell application "Finder" to duplicate this_folder to target_folder
然后将脚本作为普通脚本运行,它将完全将文件夹复制到目标位置。
另一方面,如果您只想复制项目,则可以进行以下更改:
set this_folder to choose folder with prompt "Select source folder:" with multiple selections allowed
set target_folder to choose folder with prompt "Select backup folder:"
tell application "Finder"
set these_items to list folder of this_folder without invisibles
repeat with i from 1 to count of these_items
set ItemX to item i of these_items
set ItemX to (this_folder & ItemX as string) as alias
duplicate ItemX to target_folder
end repeat
end tell
无论哪种方式,您最终都会得到一个重复。
答案 1 :(得分:0)
在下面的示例中,目标文件夹在桌面上被设置为“目标”文件夹。您可以根据需要进行调整。
警告:如果目标文件夹不存在,此示例将无法解决!
on adding folder items to this_folder after receiving these_items
set DestFolder to ((path to desktop folder) as string) & "Target:"
tell application "Finder" to duplicate these_items to folder DestFolder
end adding folder items to
每次您将文件拖放到该脚本的文件夹链接中时,这些文件将被复制到Target。