Could anybody help me please
I need to rename a folder of files, the filename format is:
a word 948321.jpg
another word 83746.jpg
etc
I need to be able to remove the words from the beginning of the filename so just leaving the files named as:
948321.jpg
83746.jpg
I have tried many file renaming progs but none of them allow for wildcard cap and lowercase letters at the beginning of filenames to be removed.
I am completely new to applescripting and would appreciate any help with this problem
: Could anybody help me please
: I need to rename a folder of files, the filename format is: a word 948321.jpg
: another word 83746.jpg
: etc
: I need to be able to remove the words from the beginning of the filename so
: just leaving the files named as: 948321.jpg
: 83746.jpg
: I have tried many file renaming progs but none of them allow for wildcard cap
: and lowercase letters at the beginning of filenames to be removed.
: I am completely new to applescripting and would appreciate any help with this
: problem
set nList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
set fName to "another word 83746.jpg" -- just for testing.
-- fName is the name of your file
set nName to ""
repeat with i from 1 to length of fName
if character i of fName is in nList then
set nName to nName & (characters i thru length of fName)
exit repeat
end if
end repeat
-- use nName to rename this file
You could also try playing with: set fName to “another word 83746.jpg” – just for testing
set newName to fName’s word -2 & “.” & fName’s word -1 That depends, of course, on there always being a space (or a period) before the number.
Andreas
try this
I assume that the convention is like this test 12345.jpg with a space after the first word.
set job_list to list folder “hard disk:jpeg folder:” as list without invisibles
repeat with job1 in job_list
set applescript’s text item delimiters to " "
set new_name to text item 2 of job1
copyfile “hard disk:jpeg folder:” & job1 to “Hard disk:new jpeg folder:” & new_name replacing yes
Make sure you have two folders one with the jpegs in and an empty one to copy them to with the new name. just change the script to your folders.
You also need to download jon’s commands of this site and put it in your scripting additions folder.
I have tested this on my mac and it works fine 2000 files in less than 10 mins.
Regards
Rick
Hi Cuneyt Ocaklilar
Thanks for your response, I apologize for my ignorance with this but I have been playing with the code you kindly supplied for a day and a half now and I can sort of understand the theory of what you have written but I just cannot get this to run. bearing in mind I have no experience of applescript could you please supply me with an “idiots guide” to setting this script up to run on a folder of files. Again I apologize for having to ask this, but It is not through lack of effort that I have to ask but until I can get at least one script to run I just don’t see how I can start to teach myself more.
thanks in advance
Steve
: Hi Cuneyt Ocaklilar
: Thanks for your response, I apologize for my ignorance with this but I have
: been playing with the code you kindly supplied for a day and a half now
: and I can sort of understand the theory of what you have written but I
: just cannot get this to run. bearing in mind I have no experience of
: applescript could you please supply me with an “idiots guide” to
: setting this script up to run on a folder of files. Again I apologize for
: having to ask this, but It is not through lack of effort that I have to
: ask but until I can get at least one script to run I just don’t see how I
: can start to teach myself more.
: thanks in advance
: Steve
property nList : {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
on open these_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set the item_info to info for this_item
if folder of the item_info is true then
tell application "Finder"
try
set the folder_items to ¬
every file of the entire contents of ¬
this_item as alias list
on error -- Single item, coerce to alias and list
set the folder_items to ¬
every file of the entire contents of ¬
this_item as alias as list
end try
end tell
repeat with z from 1 to the count of the folder_items
set this_file to item z of the folder_items
my process_item(this_file)
end repeat
else if alias of the item_info is false then
my process_item(this_item)
end if
end repeat
end open
on process_item(this_item)
set nName to ""
tell application "Finder" to set fName to name of this_item
repeat with i from 1 to length of fName
if character i of fName is in nList then
set nName to nName & (characters i thru length of fName)
exit repeat
end if
end repeat
tell application "Finder"
try
set name of this_item to nName
end try
end tell
end process_item
That did the trick
This works fine, thank you very much for your time and effort, there is a problem with running this across a network, it seems to be something to do with the way the script has to create aliases to keep track of the changing filenames, if there is a quick fix I would be interested in your suggestions, otherwise I can always copy all files to be renamed to my hard disk for renaming.
Thank you again for your interest
Steve
: That did the trick
: This works fine, thank you very much for your time and effort, there is a
: problem with running this across a network, it seems to be something to do
: with the way the script has to create aliases to keep track of the
: changing filenames, if there is a quick fix I would be interested in your
: suggestions, otherwise I can always copy all files to be renamed to my
: hard disk for renaming.
: Thank you again for your interest
: Steve
If I understand you correctly, you want to choose a folder to process over a network. The following script will let you to choose a folder to rename its items, if you double click to open it. It will still accept the drag drop support. You can use it by either way but I couldn’t test it over a network.
property nList : {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
on run
tell application "Finder"
set these_items to every item of (choose folder) as alias list
end tell
DoIt(these_items)
end run
on open these_items
DoIt(these_items)
end open
on process_item(this_item)
set nName to ""
tell application "Finder" to set fName to name of this_item
repeat with i from 1 to length of fName
if character i of fName is in nList then
set nName to nName & (characters i thru length of fName)
exit repeat
end if
end repeat
tell application "Finder"
try
set name of this_item to nName
end try
end tell
end process_item
on DoIt(these_items)
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set the item_info to info for this_item
if folder of the item_info is true then
tell application "Finder"
try
set the folder_items to ¬
every file of the entire contents of ¬
this_item as alias list
on error -- Single item, coerce to alias and list
set the folder_items to ¬
every file of the entire contents of ¬
this_item as alias as list
end try
end tell
repeat with z from 1 to the count of the folder_items
set this_file to item z of the folder_items
my process_item(this_file)
end repeat
else if alias of the item_info is false then
my process_item(this_item)
end if
end repeat
end DoIt
Thanks very much Cuneyt Ocaklilar
This now works perfectly across the network, thank you once again for your help it is much appreciated, I will study your code and see what I can learn from it.
Steve
Cuneyt Ocaklilar you are an AppleScript god!
I have been following this thread and am amazed at how kindly you handled the situation.
:mrgreen: with envy.
Dave
This is a great resource! I was wondering if anyone could tell me how to adjust the code to allow me to place additional text in the middle of a file name. For example, a file named “50002-A.jpg” and I would like to insert “-PMB” between the number and the other hyphen.
Thank you,
Steve
set fName to "50002-A.jpg" -- just for testing.
-- fName is the name of your file
set nName to ""
repeat with i from 1 to length of fName
if character i of fName is "-" then
set nName to (characters 1 through (i - 1) of fName) & "-PMB" & (characters i through (length of fName) of fName)
exit repeat
end if
end repeat
display dialog nName as text -- just for testing.
-- use nName to rename this file