• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: delete first 3 characters in a file name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: delete first 3 characters in a file name


  • Subject: Re: delete first 3 characters in a file name
  • From: Michelle Steiner <email@hidden>
  • Date: Thu, 9 Dec 2004 10:28:09 -0700

On Dec 9, 2004, at 9:40 AM, Jan-Bultereys wrote:

select a couple of files in a folder all starting with 001_test, 103_test2, 203_test3 for example
then rename them to test1, test2, test3.....

This should work:

set foo to choose folder
set text item delimiters to "_"
tell application "Finder"
repeat with i from 1 to count (get files of foo)
set name of file i of foo to (text item 2 of (get name of file i of foo))
end repeat
end tell
set text item delimiters to ""


However, when I run it, I get a very weird error.  Here is the log:

ell current application
choose folder
alias "Dora:Users:michelle:Desktop:aa:"
end tell
tell application "Finder"
get every file of alias "Dora:Users:michelle:Desktop:aa:"
{internet location file "001_test.webloc" of folder "aa" of folder "Desktop" of folder "michelle" of folder "Users" of startup disk, document file "103_test2.html" of folder "aa" of folder "Desktop" of folder "michelle" of folder "Users" of startup disk, document file "203_test3.html" of folder "aa" of folder "Desktop" of folder "michelle" of folder "Users" of startup disk}
get name of file 1 of alias "Dora:Users:michelle:Desktop:aa:"
"001_test.webloc"
set name of file 1 of alias "Dora:Users:michelle:Desktop:aa:" to "test.webloc"
"test.webloc"
get name of file 2 of alias "Dora:Users:michelle:Desktop:aa:"
"203_test3.html"
set name of file 2 of alias "Dora:Users:michelle:Desktop:aa:" to "test3.html"
"test3.html"
get name of file 3 of alias "Dora:Users:michelle:Desktop:aa:"
"test3.html"
"Can't get text item 2 of \"test3.html\"."


When it is supposed to change item 2, it changes item 3, so when it tries to change item 3, it errors because the name doesn't have the underscore.

--
Support our troops.  Bring them home NOW!

_______________________________________________
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


References: 
 >delete first 3 characters in a file name (From: "Jan-Bultereys" <email@hidden>)

  • Prev by Date: Re: Scripting Wireless Connectivity
  • Next by Date: Re: delete first 3 characters in a file name
  • Previous by thread: delete first 3 characters in a file name
  • Next by thread: Re: delete first 3 characters in a file name
  • Index(es):
    • Date
    • Thread