It’s your duty to edit the script to match the location of the source files and the location of the destination one.
(1) At this time you said that the source file is named :
Wyoming_2010_Identification Card_AllAges_Default_FrontUV.jpg
This is a filename not a filepath.
As I am not a sooth sayer I can’t guess what is the entire path.
You wrote : I have a main folder, RB_NA with 2 subfolders. JPG and ZOOM.
RB_NA is a folder name, not a folder path
(2) At this time you said that the destination folder is :
NA_Docs/Wyoming/2010/Identification Card_AllAges_Default/jpg.
Must I understand that NA_Docs is the name of harddisk dedicated to the storage of your files or is it, as I guessed, the name of a folder containing the hierarchy : Wyoming/2010/Identification Card_AllAges_Default/jpg ?
You know the answers but I don’t.
Here is a new draft :
# Define the folder in which are stored the files to move
set begOfSourceFolderPath to "path:to:the:folder:theMainFolder"
if begOfSourceFolderPath does not end with ":" then set begOfSourceFolderPath to begOfSourceFolderPath & ":"
# Define the beg of the path to destination hierarchy
set mainDestFolder to "path:of:the:main:folder:of:the:destination:NA_Docs"
if mainDestFolder does not end with ":" then set mainDestFolder to mainDestFolder & ":"
set mainDestFolder to POSIX path of mainDestFolder
tell application "System Events"
set theFolders to path of every folder of folder begOfSourceFolderPath
# Loop across the different source folders
repeat with aFolder in theFolders
# Loop across the two subfolders containing the picture files
repeat with folderName in {"JPG:", "ZOOM"}
set folderName to folderName as text
if folderName does not end with ":" then set folderName to folderName & ":"
set sourceFolder to aFolder & folderName
# Extract the list of picture fileNames
set theFiles to (name of every file of folder sourceFolder whose type identifier is "public.jpeg")
# Loop moving the files one by one
repeat with aFile in theFiles
my storeIt(aFile, sourceFolder, mainDestFolder, folderName)
end repeat # aFile
end repeat # folderName
end repeat
end tell # System Events
#=====
# Handler treating a file
on storeIt(theSourceName, theSourceFolder, theMainDestFolder, theFolderName)
# split the name upon the underscore character
set enListe to my decoupe(theSourceName, "_")
# build the end of the destination hierarchy
set endOfPath to my recolle(items 1 thru 2 of enListe, "/") & "/" & my recolle(items 3 thru -2 of enListe, "_") & "/" & text 1 thru -2 of theFolderName & "/" & theSourceName
set quotedSourcePath to quoted form of POSIX path of (theSourceFolder & theSourceName)
# Copy the file in the folder hierarchy, creating it if needed
do shell script "ditto " & quotedSourcePath & space & quoted form of (theMainDestFolder & endOfPath)
# Delete the source File
do shell script "rm " & quotedSourcePath
end storeIt
#=====
on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to "" & l
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
It’s your duty to edit the two instructions :
set begOfSourceFolderPath to “path:to:the:folder:RB_NA”
set mainDestFolder to POSIX path of (“path:of:the:main:folder:of:the:destination:NA_Docs”) # Yesterdays it was “ALL_PICTURES”
replacing the fake pathnames by the true ones.
EDITED ONE MORE TIME TO MATCH THE COMPLEMENTARY INFOS !
Yvan KOENIG (VALLAURIS, France) mercredi 9 avril 2014 11:35:43