Hellooo!
I’m stuck!
Does anyone know how to add text, eg “small_” at the beginning of a bunch of files in a specific folder?
or even better…
Does anyone know how to add text, eg “small_” at the beginning of a bunch of files before I move them to a specific folder?
/Jonas
==============This is how the script looks like at the moment ================
set PathPrefix to (path to desktop as string)
set jpg_in to (PathPrefix & “TheFolder:in”) as string
set jpg_out to (PathPrefix & “TheFolder:out”) as string
tell application “Finder”
move (items of folder jpg_in whose creation date > (current date) - (10 * days)) to folder jpg_out with replacing
end tell
Try this:
set PathPrefix to (path to desktop as text)
set jpg_in to (PathPrefix & "theFolder:in:") as alias -- this assumes the files and folders actually exist
set jpg_out to (PathPrefix & "theFolder:out:") as alias -- it will fail if they don't.
tell application "Finder"
--move (items of folder jpg_in whose creation date > (current date) - (10 * days)) to folder jpg_out with replacing
set filesToMove to (files of folder jpg_in whose creation date > (current date) - (10 * days)) as alias list
repeat with aFile in filesToMove -- iterate thru the files
set tmp to (contents of aFile) -- get the file's alias instead of the list reference
set name of tmp to ("small_" & (name of tmp)) -- rename it
end repeat
move items of filesToMove to folder jpg_out with replacing
end tell
I could not test this as I don’t have your folder structure or files. However it looks like it will work.
It expects a folder on your desktop named “theFolder” which contains a folder named “in” and a folder named “out”. It grabs the file aliases from the “in” folder and then loops thru them renaming each one. After the renaming is complete, it moves them.
If you do this sort of thing on a routine basis have a look at the “File Buddy” application. It’s made for just this sort of manipulation.
http://www.skytag.com/filebuddy/en/index.html
Av8TnTek.
You are the sunshine of my life! A big hug to you 
/Jonas
I even manage to move all the files from the nested folders and rename the files after moving 
========================================================================
set PathPrefix to (path to desktop as alias)
set test_out to (“Disk:out”) as alias
set test_in to (“Disk:in”) as alias
tell application “Finder”
set filesToMove to (every file in entire contents of folder test_out whose creation date > (current date) - (20 * days)) as alias list
move items of filesToMove to folder test_in with replacing
set filesToRename to (files of folder test_in) as alias list
repeat with aFile in filesToRename
set tmp to (contents of aFile)
set name of tmp to ("small_" & (name of tmp))
end repeat
end tell
As you are using the keyword folder in your script, the syntax might work but is not correct because it’s actually a double reference.
In this case all path references are supposed to be (HFS) string paths
set PathPrefix to (path to desktop as text)
set test_out to ("Disk:out:") -- it's good habit to specify a path to a folder with a trailing colon
set test_in to ("Disk:in:")
PS: path to desktop returns an alias specifier anyway so the alias coercion is useless
Thank you Stefan!
The script now look like this. But the script is really slow and if there is too meny nested folders I get a time out message.
Automator is fast but always loose connection with the network volumes.
=================================================
set PathPrefix to (path to desktop)
set test_out to (“theFolder:in:”)
set test_in to (“ttheFolder:out:”)
tell application “Finder”
set filesToMove to every file in entire contents of folder test_out whose creation date > (current date) - 1 * days
duplicate items of filesToMove to folder test_in with replacing
set filesToRename to (files of folder test_in)
repeat with aFile in filesToRename
set tmp to (contents of aFile)
set name of tmp to ("small_" & (name of tmp))
end repeat
end tell
using a shell script to find and copy the files is much faster
set test_out to ("theFolder:in:")
set test_in to ("ttheFolder:out:")
do shell script "/usr/bin/find " & quoted form of POSIX path of test_out & " -type f ! -name '.*' -Btime -1d -print -exec /bin/cp {} " & quoted form of POSIX path of test_in & " \\;"
tell application "Finder"
set filesToRename to (files of folder test_in)
repeat with aFile in filesToRename
set tmp to (contents of aFile)
set name of tmp to ("small_" & (name of tmp))
end repeat
end tell