リストファイルからコピー

仕様を読み違えてたので修正

指定フォルダ中からリストを作成し、同名のeps形式を検索。
見つかれば収集用の指定フォルダにコピー、なければ収集用フォルダ内にサブフォルダを作りコピーする。

```AppleScript 
(*
		リストのファイルを検索しコピーするスクリプト

		2016-02-28		v0.1
		2016-02-29		v0.2	
*)



set FindExt to "jpg"
set RepExt to "eps"

--画像リスト
set ImportFolder to POSIX path of (choose folder with prompt "入稿フォルダを選択してください")
set FileList to do shell script "ls " & ImportFolder
set FileList to paragraphs of FileList

--検索フォルダ
--set FindFolder to "Macintosh HD:Users:admin:Desktop:" as alias
set FindFolder to choose folder with prompt "検索するフォルダを選択してください"
set FindFolder to POSIX path of FindFolder

--収集フォルダ
--set CollectFolder to "Macintosh HD:Users:admin:Desktop:EPS:" as alias
set CollectFolder to choose folder with prompt "コピー先のフォルダを選択してください"
set CollectFolder to POSIX path of CollectFolder

--切り抜かれてない画像フォルダ
try
	do shell script "mkdir " & CollectFolder & FindExt
end try
set notClipFolder to CollectFolder & FindExt


repeat with aFile in FindList
	
	if aFile is not "" then
		set aFile to aFile as Unicode text
		
		--検索ファイル名
		set FindFile to my Delimiters(aFile, FindExt, RepExt) as Unicode text
		
		--画像検索
		set FindPath to myFind(FindFolder, FindFile)
		
		if FindPath is not "" then
			myCopy(FindPath, CollectFolder)
		else
			myCopy(FindPath, notClipFolder)
		end if
		
	end if
	
end repeat

beep 2



on myFind(targetFolder, FindFile)
	set shcom to "find " & quoted form of targetFolder & " -iname " & quoted form of FindFile
	--display dialog shcom
	set FindPath to do shell script shcom
	return FindPath
end myFind

on myCopy(FindPath, CollectFolder)
	set shcom to "cp " & quoted form of FindPath & space & quoted form of CollectFolder
	--display dialog "cpcom " & shcom
	set FindPath to do shell script shcom
end myCopy

on Delimiters(theText, serchStr, replaceStr)
	set OriginalDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to serchStr
	set theText to text items of theText
	set AppleScript's text item delimiters to replaceStr
	set theText to theText as string
	set AppleScript's text item delimiters to OriginalDelimiters
	return theText
end Delimiters
```

画像リストファイルがあると思ってた…


```AppleScript 
(*
		リストのファイルを検索しコピーするスクリプト

		2016-02-28		v0.1
*)



set errList to {}
set FindExt to "jpg"
set RepExt to "eps"

--画像リスト
--set FindList to "JT1-001E.jpg\rJT1-002A.jpg\rJT1-022A.jpg\r0000.jpg"
set ListFile to choose file with prompt "リストファイルを選択してください"
set FindList to do shell script "cat " & quoted form of POSIX path of ListFile
set FindList to paragraphs of FindList

--検索フォルダ
--set FindFolder to "Macintosh HD:Users:admin:Desktop:" as alias
set FindFolder to choose folder with prompt "検索するフォルダを選択してください"
set FindFolder to POSIX path of FindFolder

--収集フォルダ
--set CollectFolder to "Macintosh HD:Users:admin:Desktop:EPS:" as alias
set CollectFolder to choose folder with prompt "コピー先のフォルダを選択してください"
set CollectFolder to POSIX path of CollectFolder

--切り抜かれてない画像フォルダ
try
	do shell script "mkdir " & CollectFolder & FindExt
end try
set notClipFolder to CollectFolder & FindExt


repeat with aFile in FindList
	
	if aFile is not "" then
		set aFile to aFile as Unicode text
		
		--検索ファイル名
		set FindFile to my Delimiters(aFile, FindExt, RepExt) as Unicode text
		
		--画像検索
		set FindPath to myFind(FindFolder, FindFile)
		
		if FindPath is not "" then
			myCopy(FindPath, CollectFolder)
		else
			set FindPath to myFind(FindFolder, aFile)
			if FindPath is not "" then
				myCopy(FindPath, notClipFolder)
			else
				set errList to errList & aFile & return
			end if
		end if
		
	end if
	
end repeat

beep 2
if errList is not "" then
	display dialog "見つからないファイルがありました" buttons {"OK"} default button "OK" with icon caution
	do shell script "echo " & errList & " > " & CollectFolder & "見つからなかったファイル.txt"
end if


on myFind(targetFolder, FindFile)
	set shcom to "find " & quoted form of targetFolder & " -iname " & quoted form of FindFile
	--display dialog shcom
	set FindPath to do shell script shcom
	return FindPath
end myFind

on myCopy(FindPath, CollectFolder)
	set shcom to "cp " & quoted form of FindPath & space & quoted form of CollectFolder
	--display dialog "cpcom " & shcom
	set FindPath to do shell script shcom
end myCopy

on Delimiters(theText, serchStr, replaceStr)
	set OriginalDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to serchStr
	set theText to text items of theText
	set AppleScript's text item delimiters to replaceStr
	set theText to theText as string
	set AppleScript's text item delimiters to OriginalDelimiters
	return theText
end Delimiters

```