• 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
Replace names of files in different folders
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Replace names of files in different folders


  • Subject: Replace names of files in different folders
  • From: Jan Bultereys <email@hidden>
  • Date: Tue, 11 Apr 2006 19:05:27 +0200
  • Thread-topic: Replace names of files in different folders

Title: Replace names of files in different folders
Hi does anyone have a better solution:

This works but it’s very unstable:
When I replace the “source folder” with the fixed folder it does not work, and I really don’t have a clue why?
This is what I want:
2 folders with “files” --- replace the names with other names.
1 st FOLDER:
Eg (OH1H-001) - Replace to (GF1F-001)
2 nd FOLDER
Eg (OH1H-001) - Replace to (GW1W-001)

property searchStrings : {"OG1H", " OG1H"}
property replacementStrings : {"GW1W", " GW2W"}

global search_string
global replacement_string

tell application "Finder"
    --set the source_folder to "FileTransfer_BEL:EUROPEAN_PAGES:BELGIUM_FR:" as alias
   set source_folder to choose folder with prompt "BELGIUM_FR"
    repeat with x from 1 to (get count of items in searchStrings)
        set search_string to (item x of searchStrings)
        set replacement_string to (item x of replacementStrings)
        my createList(source_folder)
    end repeat
end
tell

on createList(item_list)
    set the the_items to list folder item_list without invisibles
   set item_list to item_list as string
   repeat with i from 1 to number of items in the the_items
       set the_item to item i of the the_items
       set the_item to (item_list & the_item) as alias
       set this_info to info for the_item
       --zelf--
       --set the this_info to name of the_item as text
       set the item_name to the (name of this_info) as text -- EDITED HERE
       if item_name contains search_string then
           set changedFile to ((the_item as string) & return)
            my replaceString(item_name, the_item, search_string, replacement_string)
        end if
       if folder of this_info is true then
           my createList(the_item)
        end if
   end repeat
end
createList

on replaceString(current_name, the_item, search_string, replacement_string)
    set AppleScript's text item delimiters to search_string
   set the text_item_list to every text item of the current_name
   set AppleScript's text item delimiters to replacement_string
   set the new_item_name to the text_item_list as string
   set AppleScript's text item delimiters to ""
    my set_item_name(the_item, new_item_name)
end replaceString

on set_item_name(this_item, new_item_name)
    tell application "Finder"
        set the parent_container_path to (the container of this_item) as text
       --    if not (exists item (the parent_container_path & new_item_name)) then
       --    try
       set the name of this_item to new_item_name
       --        end try
       --    end if
   end tell
end
set_item_name



property searchStrings2 : {"OG1H", " OG2H"}
property replacementStrings2 : {"GF1F", "GF2F"}

global search_string2
global replacement_string2

tell application "Finder"
    --set the source_folder2 to "FileTransfer_BEL:EUROPEAN_PAGES:BELGIUM_NL:" as alias
   set source_folder2 to choose folder with prompt "BELGIUM_NL"
    repeat with x from 1 to (get count of items in searchStrings2)
        set search_string2 to (item x of searchStrings2)
        set replacement_string2 to (item x of replacementStrings2)
        my createList2(source_folder2)
    end repeat
end
tell

on createList2(item_list2)
    set the the_items2 to list folder item_list2 without invisibles
   set item_list2 to item_list2 as string
   repeat with i from 1 to number of items in the the_items2
       set the_item2 to item i of the the_items2
       set the_item2 to (item_list2 & the_item2) as alias
       set this_info2 to info for the_item2
       --zelf--
       --set the this_info to name of the_item as text
       set the item_name2 to the (name of this_info2) as text -- EDITED HERE
       if item_name2 contains search_string2 then
           set changedFile2 to ((the_item2 as string) & return)
            my replaceString2(item_name2, the_item2, search_string2, replacement_string2)
        end if
       if folder of this_info2 is true then
           my createList2(the_item2)
        end if
   end repeat
end
createList2

on replaceString2(current_name2, the_item2, search_string2, replacement_string2)
    set AppleScript's text item delimiters to search_string2
   set the text_item_list2 to every text item of the current_name2
   set AppleScript's text item delimiters to replacement_string2
   set the new_item_name2 to the text_item_list2 as string
   set AppleScript's text item delimiters to ""
    my set_item_name2(the_item2, new_item_name2)
end replaceString2

on set_item_name2(this_item2, new_item_name2)
    tell application "Finder"
        set the parent_container_path2 to (the container of this_item2) as text
       --    if not (exists item (the parent_container_path & new_item_name)) then
       --    try
       set the name of this_item2 to new_item_name2
       --        end try
       --    end if
   end tell
end
set_item_name2




 _______________________________________________
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: Replace names of files in different folders
      • From: Emmanuel <email@hidden>
  • Prev by Date: Re: Scripting Mail
  • Next by Date: Re: Scripting Mail
  • Previous by thread: Re: Scripting Mail
  • Next by thread: Re: Replace names of files in different folders
  • Index(es):
    • Date
    • Thread