Re: slow folder action script
Re: slow folder action script
- Subject: Re: slow folder action script
- From: kai <email@hidden>
- Date: Mon, 9 May 2005 00:56:59 +0100
On Sunday, May 8, 2005, at 08:12 am, Yvan KOENIG wrote:
I tried to help someone with this folder actions script:
--[Script ranger dans sous-dossiers]
property monDossier : "Mes dossiers"
property debutNom : "mes MP3s #"
property limite : 100
on adding folder items to this_folder after receiving added_items
tell application "Finder"
set dossier to ("" & this_folder & monDossier) as alias
set lesDossiers to (every folder in dossier)
if lesDossiers is {} then set lesDossiers to {my
cree1dossier(dossier, debutNom & "001")}
set leDernier to (lesDossiers's item 1) as text
repeat with d in lesDossiers
set n_d to d as text
if n_d > leDernier then set leDernier to n_d
end repeat
set cai to count of added_items
set vieuxCompte to (count of (every item in folder leDernier))
if vieuxCompte + cai is not greater than limite then
(* no need to create a new folder *)
repeat with f in added_items
move f as alias to folder leDernier
end repeat
else
set knt1 to limite - vieuxCompte
if vieuxCompte is not limite then
(* fills the existing subfolder *)
repeat with i from 1 to knt1
move (added_items's item i) as alias to folder leDernier
end repeat -- with i …
end if -- vieuxCompte is not limite
repeat
(* create a new folder *)
set oldnum to (text -4 thru -2 of leDernier) as number
set newNum to oldnum + 1
set leDernier to (my cree1dossier(dossier, debutNom & text -3 thru -1
of ("000" & newNum))) as text
set reste to cai - knt1
if reste > limite then
(* fills the new folder *)
repeat with i from 1 to limite
move (added_items's item (i + knt1)) as alias to folder leDernier
end repeat -- with i …
set knt1 to knt1 + limite
else
(* move the remaining files *)
repeat with i from 1 to reste
move (added_items's item (i + knt1)) as alias to folder leDernier
end repeat -- with i …
exit repeat
end if -- reste > limite
end repeat
end if -- vieuxCompte + cai is not greater than limite
end tell -- to Finder
end adding folder items to
on cree1dossier(c, n)
tell application "Finder"
set d to make new folder at c with properties {name:n}
end tell
return d
end cree1dossier
--[/Script]
Dropped files are moved in subfolders whose contents is limited to 100
files.
Alas, the user drops hundreds of files at a time and the script
appears to be slow.
Is one of you able to fasten it or is it no other soluce than saying :
drop smaller sets of files?
Moving hundreds of files will inevitably take some time, Yvan -
although you can speed up the process by moving them in batches, rather
than individually. Try something like this (sorry about the mishmash of
languages):
-------------------
property monDossier : "Mes dossiers"
property debutNom : "mes MP3s #"
property limite : 100
to getDossier at dropFolder
tell application "Finder" to try
dropFolder's folder monDossier
on error
make new folder at dropFolder with properties {name:monDossier}
end try
end getDossier
to makeNewFolder at dossier from currFolder
set n to 1 + (currFolder's (text -3 thru -1))
tell application "Finder" to repeat
try
set newName to debutNom & ((1000 + n) as string)'s text -3 thru -1
dossier's folder newName
set n to n + 1
on error
make new folder at dossier with properties {name:newName}
return {newName, limite}
end try
end repeat
end makeNewFolder
to getCurrFolder at dossier
tell application "Finder" to tell (debutNom & ((1000 + ¬
(count dossier's folders)) as string)'s text -3 thru -1) to try
tell dossier's folder it to set fileLimit to limite - (count files)
if fileLimit is 0 then error
{it, fileLimit}
on error
my (makeNewFolder at dossier from it)
end try
end getCurrFolder
on adding folder items to this_folder after receiving added_items
set dossier to getDossier at this_folder
tell application "Finder"
set {currFolder, fileLimit} to my (getCurrFolder at dossier)
repeat
if (count added_items) > fileLimit then
move items 1 thru fileLimit of added_items to dossier's folder
currFolder
set added_items to items (fileLimit + 1) thru -1 of added_items
set {currFolder, fileLimit} to my (makeNewFolder at dossier from
currFolder)
else
move added_items to dossier's folder currFolder
exit repeat
end if
end repeat
end tell
end adding folder items to
-------------------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden