Re: duplicate one file
Re: duplicate one file
- Subject: Re: duplicate one file
- From: John Delacour <email@hidden>
- Date: Sat, 3 Aug 2002 14:15:49 +0100
At 11:18 am +0200 3/8/02, Emmanuel wrote:
duplicating files is the Finder's job. If you have not already, you should
have a look at the Finder's dictionary. Did you try simply:
----------------
set theFile to alias "Macintosh HD:myfile.htm"
repeat 1000 times
tell application "Finder" to duplicate theFile
end
----------------
A more sophisticated script would keep track in a list of the references of
the duplicated files, so that renaming them would be easier.
Mmm. I despair of the Finder. It has always been buggy and terribly
slow and it seems as bad as ever now.
Mirko is using OS X and this allows a lot of things that formerly had
to be done in the Finder or with the Read/Write osax (now in Standard
Addns) to be done in the shell at breakneck speed. Even without
this, it would certainly be quicker to use the read/write events to
do this job rather than the Finder. I'm not doing the testing but
I'll bet you.
This script below is a plug-n-play demo of what I mean. I have used
the read/write osax to create the file junk.html in my user
directory, though this could be done in perl or the shell just as
well, of course.
One line of perl code then creates a list of filenames to be passed
to the shell and a simple loop in the shell to duplicate the files
and open the directory to reveal the mew files. The process in the
terminal would go something like this -- which you will notice does
not look much like Applecript...
perl -e 'for(1..20) { printf q~junkd%s.html ~, $_ }'
cd
for newfile in junk0001.html junk0002.html
do
cp junk.html $newfile
done
open `PWD`
(* AS SCRIPT TO MULTIPLICATE A FILE *)
set varDirectory to the path to the current user folder
set varPathname to "" & varDirectory & "junk.html"
open for access file varPathname
close access file varPathname
(* you now have "junk.html" if you didn't before
Now get perl to build a list of filenames*)
--
set pl to " 'for(1..20) {printf q~junkd%s.html ~, $_}' "
set ls to do shell script "perl -e" & pl
--> "junk0001.html junk0002.html junk0003.html etc
set sh to " sh ; cd ; " -- use sh shell ; go to home directory
set sh to sh & " for newfile in " & ls -- loop through ls
set sh to sh & " ; do ;" -- start loop
set sh to sh & " cp junk.html $newfile ;" -- create the dupl. files
set sh to sh & " done ;" -- end loop
set sh to sh & " open `PWD` ;" -- open the directory
do shell script sh
(* JD *)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.