Randomize filenames in a folder

Hi all,

I am an artist working on a new rotoscope animation - experimenting with timeline structure. I work on large folders of tiff files individually running actions and then reassemble these via quicktime into video clips.

I would like to produce a clip which plays back a 20 second clip with the frames in a totally random order - I have been advised that this can only be done with apple script.

so the action would be to take folder x and to rename each of the files numerically in a random fashion without duplication -

can anybody help?

I would be very grateful and will upload video results online when complete

thanks

Paul

Mac Book Pro 2.33 GHz Intel Core Duo, Mac OS X (10.4.10), 2GB SDRAM, Wacom Intuos 3, quicksilver, FC Studio 2, CS3 Design Premium, AE CS3 Pro

Posted on Sep 16, 2007 1:37 PM

Reply
7 replies

Sep 16, 2007 3:27 PM in response to paulsimon

I would like to produce a clip which plays back a 20 second clip with the frames in a totally random order - I have been advised that this can only be done with apple script.


I don't know that only is the right word, but it's certainly a possibility.

so the action would be to take folder x and to rename each of the files numerically in a random fashion without duplication -


For simplicity's sake, I'd create a new folder and move the files into that folder as you go - it's a far easier way of avoiding duplicates:

tell application "Finder"
set destFolder to (make new folder as desktop with properties {name: "new animation"})
set sourceFolder to (choose folder with prompt "Please select the source images folder")
set numFiles to (number of files of folder sourceFolder)
repeat with i from 1 to numFiles
set newFile to (move some file of folder sourceFolder to folder destFolder)
set name of newFile to (i & ".tiff")
end repeat
end tell


The above script first creates a new folder on your desktop where the random files will go. It asks for the source images folder, then iterates through based on the number of files in that folder.
On each iteration through the loop it grabs 'some file' of the source folder. That's what gives you the random element. Once the file is moved it's renamed based on the current number of files that have been moved.

There are doubtless many more ways of achieving the same result, and this script has no error checking (e.g. makes sure the destFolder can be created, files can be renamed, etc.), but it should be a good starting point.

If you're worried about ending up with a new folder, you could add commands at the end to delete the (now empty) source folder, and rename/move the destFolder into the sourceFolder's location.

Sep 17, 2007 12:28 AM in response to Camelot

Hi,
Thank you for your help

although being a scripting Luddite I can't fully operate this and I'm not totally clear which peramiters I should change and which is a command

Iv got this far

tell application "Finder"
set destFolder to {name:"new animation"}
set sourceFolder to {name:"photocopy"}
set numFiles to 251
repeat with i from 1 to numFiles
set newFile to (move some file of folder sourceFolder to folder destFolder)
set name of newFile to (i & ".tiff")
end repeat
end tell

but it says Apple script error. Finder got an error: Can't get some file of folder {name:"photocopy"}.

and it highlights the line:
move some file of folder sourceFolder to folder destFolder

thanks for your help

Sep 17, 2007 1:41 AM in response to paulsimon

The script I posted should work as-is.

It will create a new folder on your desktop for the randomized files, and it will prompt you to locate the folder containing the originals. You shouldn't need to make any changes.

If you do want to hard-code the folders, though, you need to give the script the full path to the folder in the form:

tell application "Finder"
set destFolder to folder "HD:Users:paul:Desktop:destination:"
set sourceFolder to folder "HD:Users:paul:Desktop:source:"
...
end tell


You'll need to fill in the complete path to your directories, though, bearing in mind that the above code will not create the destination directory if it doesn't already exist - it will require that the directory is there before you run the script (which is why my earlier example creates a new directory)

Sep 17, 2007 9:31 AM in response to paulsimon

You're right, there were a couple of typos in my original script. My bad.

Try this one:

tell application "Finder"
set destFolder to (make new folder at desktop with properties {name:"new animation"})
set sourceFolder to (choose folder with prompt "Please select the source images folder")
set numFiles to (number of files of folder sourceFolder)
repeat with i from 1 to numFiles
set newFile to (duplicate some file of folder sourceFolder to destFolder)
set name of newFile to (i & ".tiff" as text)
end repeat
end tell

Sep 17, 2007 11:58 AM in response to Camelot

Thank you so much that is fantastic - I have been looking all summer for a way to do this. really pleased - have uploaded the first test at www.paulsimonrichards.co.uk/randomscript.html

incidently the sound it makes when processing is manic - is there a way of scripting in to turn the sound of the copy off during this script?

I will run it for huge folders of files

thanks a lot

Paul

Message was edited by: paulsimonrichards

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Randomize filenames in a folder

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.