• 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: Verify if name contains an element of a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Verify if name contains an element of a list


  • Subject: Re: Verify if name contains an element of a list
  • From: kai <email@hidden>
  • Date: Wed, 19 Apr 2006 19:57:59 +0100


On 19 Apr 2006, at 19:30, stephan wrote:

Is there a way I can use AppleScript to verify if the name of a file or a
folder contains an element in a list?


Something like:

myListofChar = {"/", "\", "*", "?", "|"}

if FileName contains a element of myListofChar then


I need to identify which element of the list and replace it by something
else.

To replace all occurrences with a single character:

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

to switch_chars of someText from searchList to replaceChar
	set tid to text item delimiters
	repeat with i in searchList
		if i is in someText then
			set text item delimiters to i
			set someText to someText's text items
			set text item delimiters to replaceChar
			set someText to someText as string (* or unicode text *)
		end if
	end repeat
	set text item delimiters to tid
	someText
end switch_chars

set searchList to {"/", "\\", "*", "?", "|"}
set replaceChar to "_"
set someText to "*may* be this and/or that"
set newText to switch_chars of someText from searchList to replaceChar

--> "_may_ be this and_or that"

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

To replace each occurrence with a corresponding alternative:

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

to switch_chars of someText from searchList to replaceList
	set tid to text item delimiters
	repeat with i from 1 to count searchList
		set s to item i of searchList
		if s is in someText then
			set text item delimiters to s
			set someText to someText's text items
			set text item delimiters to item i of replaceList
			set someText to someText as string (* or unicode text *)
		end if
	end repeat
	set text item delimiters to tid
	someText
end switch_chars

set searchList to {"/", "\\", "*", "?", "|"}
set replaceList to {" A ", " B ", " C ", " D ", " E "}
set someText to "*may* be this and/or that"
set newText to switch_chars of someText from searchList to replaceList

--> " C may C  be this and A or that"

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

---
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: Verify if name contains an element of a list
      • From: "Adam Bell" <email@hidden>
References: 
 >Verify if name contains an element of a list (From: stephan <email@hidden>)

  • Prev by Date: Re: curl to get FTP directory listing?
  • Next by Date: Re: Check FTP file
  • Previous by thread: Verify if name contains an element of a list
  • Next by thread: Re: Verify if name contains an element of a list
  • Index(es):
    • Date
    • Thread