the CVS file has two columns: file code in one and folder name in the other. The code is the 5-number string in the file name.
As is, the code puts everything into the first folder A. Please help.
tell application "Finder"
--gets working folder and the cvs file
set folderwithfiles to choose folder
set workingFiles to get every item of (entire contents of folder (folderwithfiles)) whose name extension is "zip" as list
set FolderwithFilesString to ((folderwithfiles as string) & "data.csv")
set cvsFile to FolderwithFilesString as alias
--Main Loop
set countworkingFiles to count every item in workingFiles
repeat with i from 1 to countworkingFiles
--this section is getting values from working folder
set folderName to ""
set thefile to item i of workingFiles --complete path to the working file
set nameofthefile to (the name of thefile) --the file name
set VersiontoFind to my findVersion(nameofthefile) --gets the version from the from the file
set folderName to my findFolder(cvsFile, VersiontoFind) --Folder the file needs to in
set destinationFolder to ((folderwithfiles as string) & (folderName as string))
tell application "Finder"
move file (thefile as alias) to (destinationFolder as alias)
end tell
end repeat
end tell
on findVersion(workingFile)
set text item delimiters to "_"
set versionCode to every text item of workingFile
set theCode to item 2 of versionCode as string
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
return theCode
end findVersion
-- I did not write this I copied it from a webiste
on findFolder(the_file, versionCode)
set the_search_term to versionCode as text
set my_data to read the_file
set my_list to paragraphs of my_data as list
-- we need to make two lists: ColumnA, and ColumnB
set ColumnA_list to {}
set ColumnB_list to {}
-- this is housekeeping
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
-- /housekeeping
--make the lists
repeat with an_item in my_list
-- inserting "try" statement to catch blank lines
try
set end of ColumnA_list to text item 1 of an_item
set end of ColumnB_list to text item 2 of an_item
end try
end repeat
set AppleScript's text item delimiters to oldDelims
set the_position to indexof(versionCode, ColumnA_list)
-- "indexof" is Emmanuel Levy's routine-- thanks Emmanuel!
set the_position to the_position + 1
if the_position is 0 then
tell application "Finder"
activate
display dialog "No Files"
end tell
return
end if
-- now we know which line has the search term, so we can specify the corresponding
-- item in ColumnB_list
--set test to (item the_position of ColumnB_list)
--display dialog (test as string)
tell application "Finder"
return item the_position of ColumnB_list
end tell
end findFolder
-- I did not write this I copied it from a webiste it goes with function fineversion
-- This is Emmanuel Levy's routing
on indexof(theItem, theList) -- credits Emmanuel Levy
set text item delimiters to return
set theList to return & theList & return
set text item delimiters to {""}
try
-1 + (count (paragraphs of (text 1 thru (offset of (return & theItem & return) in theList) of theList)))
on error
0
end try
end indexof