I have a list of files in a target folder:
Example/HUVEC.csv
Example/HUVEC-1.csv
Example/HUVEC-3.3.2n-1.csv (random hash)
Example/Endo1.csv
What I'd like is to be able to create a folder called "HUVEC" if there are files that start with "HUVECxxx" in the "Example" Folder and then move the files that starts with "HUVECxxx" to the "HUVEC" Folder.
Here's what I have so far, having been modified from the simple version (see below)
set mgFilesFolder to choose folder with prompt "Where are the files stored which you would like to move to the destination?"
tell application "Finder"
set fileList to files of mgFilesFolder
repeat with aFile in fileList
set prefix to name of aFile
if prefix starts with "HUVEC" and (exists folder (HUVEC_folder)) then
move aFile to HUVEC_folder
else
set HUVEC_folder to make new folder in mgFilesFolder with properties {name:"HUVEC"}
end if
end repeat
repeat with aFile in fileList
set prefix to name of aFile
if prefix starts with "HUVEC" then move aFile to HUVEC_folder
end repeat
end tell
A more simplistic version works for one file
set mgFilesFolder to choose folder with prompt "Where are the files stored which you would like to move to the destination?"
tell application "Finder"
set fileList to files of mgFilesFolder
repeat with aFile in fileList
set prefix to name of aFile
if prefix starts with "HUVEC" and set HUVEC_folder to make new folder in mgFilesFolder with properties {name:"HUVEC"}
end if
end repeat
repeat with aFile in fileList
set prefix to name of aFile
if prefix starts with "HUVEC" then move aFile to HUVEC_folder
end repeat
end tell
but the issue with multiple files I'm quite certain is that if the folder already exists then the script fails.
Basically I think the biggest issue is how to check if a folder exists that otherwise should be created!
Thanks for any help, still relatively new at Applescript.