• 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: kai <email@hidden>
  • Date: Thu, 9 Dec 2004 22:44:23 +0000


On Thu, 9 Dec 2004 10:28:09 -0700, Michelle Steiner wrote:

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.

The sequence of files can change as filenames are changed:

{"001_test", "103_test2", "203_test3"}
{"103_test2", "203_test3", "test"}
{"103_test2", "test", "test3"}

It's probably safer to get a list and work through it:

-------------------------------

set text item delimiters to "_"
tell application "Finder" to repeat with i in (get files of (choose folder))
set i's name to text item -1 of (get i's name)
end repeat
set text item delimiters to ""


-------------------------------

---
kai

_______________________________________________
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


  • Follow-Ups:
    • Re: delete first 3 characters in a file name
      • From: Michelle Steiner <email@hidden>
  • Prev by Date: Re: [OT] Re: Smile and FruitMenu
  • Next by Date: Re: delete first 3 characters in a file name
  • Previous by thread: Re: Mail optional headers
  • Next by thread: Re: delete first 3 characters in a file name
  • Index(es):
    • Date
    • Thread