Before copy an image file .png in a destination folderI i needed to check if destination folder contains an image file .png with the same data (file name can be different).
Here is a script does the job, but a simpler way would be welcome
Code: Select all
on mouseUp
answer file "Select one image file .png"
if it = empty then exit mouseup
put it into tFileS
answer folder "Select a destination folder contains image files .png"
if it = empty then exit mouseup
put it into tFolD
put getImageWithSameDataInFolder(tFileS,tFolD) into tSameImg
if tSameImg = empty then
put "no image file .png with a same data in folder" && tFolD into tMes
else
put tFileS & cr & tSameImg & cr & "have same data" into tMes
end if
answer tMes
end mouseUp
--•• get files with same data in destination folder
function getImageWithSameDataInFolder pFileS,pFolD
put empty into rgetImageWithSameDataInFolder
set the itemdel to "/"
put item -1 of pFileS into tNameFileS
put item 1 to -2 of pFileS into tPahFolS
set the itemdel to ","
put LesDetailsFi(tPahFolS) into tDetFilesS
put LesDetailsFi(pFolD) into tDetFilesD
put urlencode(tNameFileS) into tNameImgUrl
put GetFilesSameSizeInFolder(pFileS,tNameImgUrl,tDetFilesS,tDetFilesD) into tFilesSameSize
if tFilesSameSize <>empty then --•• files with same size exits
put GetSameImgInFilesSameSize(pFileS,tFilesSameSize,pFolD) into tPathFileSameImg
if tPathFileSameImg <> empty then --•• one img with same data exists
put tPathFileSameImg into rgetImageWithSameDataInFolder
else
end if
end if
return rgetImageWithSameDataInFolder
end getImageWithSameDataInFolder
--•• get all detailed files
function LesDetailsFi pFol --•• les infos détaillées d'un fichier
local tOldDefaultFolder, tDetailedFiles
put the defaultFolder into tOldDefaultFolder
set the defaultFolder to pFol
put the detailed files into tDetailedFiles
set the defaultFolder to tOldDefaultFolder
return tDetailedFiles
end LesDetailsFi
--•• get files with same size in destination folder
function GetFilesSameSizeInFolder pFileS,pNameFi,pDetFilesS,pDetFilesD
put empty into rGetFilesSameSizeInFolder
put lineoffset(pNameFi,pDetFilesS) into tFoundLi
get line tFoundLi of pDetFilesS
put item 2 of it into tSize1
put item 3 of it into tSize2
put "*," & tSize1 & "," & tSize2 & ",*" into tFilter
filter pDetFilesD with tFilter
put pDetFilesD into rGetFilesSameSizeInFolder
return rGetFilesSameSizeInFolder
end GetFilesSameSizeInFolder
--•• get files with the same data among files of destination folder have same size
function GetSameImgInFilesSameSize pOneFile,pFiles,pFolD
put empty into rGetSameImgInFilesSameSize
put url("File:" & pOneFile) into tDataImg
repeat for each line tFileUrl in pFiles
put urldecode(item 1 of tFileUrl) into tNameFile
put pFolD & "/" & tNameFile into tPathVerif
put url("File:" & tPathVerif) into tDataImgVerif
if tDataImgVerif = tDataImg then
put tPathVerif into rGetSameImgInFilesSameSize
end if
end repeat
return rGetSameImgInFilesSameSize --(tDataImgVerif = tDataImg)
end GetSameImgInFilesSameSize
Jean-Marc