Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- acsv.applescript
- -- Prompt for headerless, .csv file and starting folder containing the files to process.-- Reads each row of the CSV into a list, splits that list item into file and folder, and-- moves the file into the appropriate folder. If a file does not exist, it skips that-- row processing, and if the folder does not exist, it will make the folder.-- Tested: macOS 10.14.5-- Reference: https://discussions.apple.com/thread/250480620-- VikingOSX, 2019-07-12, Apple Support Communities, No warranties expressed or implied.
- property delim : {","}
- property aDesktop : (path to desktop) as aliasproperty csvType : {"public.comma-separated-values-text", "public.delimited-values-text"}
- set rowItems to {}
- set afile to ""set afolder to ""
- set csvFile to (choose file with prompt "Select CSV file" of type csvType default location aDesktop without invisibles, multiple selections allowed and showing package contents)
- set start_folder to (choose folder with prompt "Text File Folder" default location aDesktop without invisibles, multiple selections allowed and showing package contents)
- set csvList to (read csvFile as text using delimiter linefeed) as listtell application "Finder"
- repeat with arow in csvList
- repeat 1 times
- -- use as many variables as you have columns in the CSV
- set {afile, afolder} to my csvParse(arow, delim) as list
- log afile
- log afolder
- try
- set check_file to (start_folder & afile) as text as alias
- on error
- exit repeat
- end try
- try
- set check_folder to (start_folder & afolder) as text as alias
- on error
- make new folder at start_folder with properties {name:afolder}
- set check_folder to (start_folder & afolder) as text as alias
- end try
- move file check_file to folder check_folder
- end repeat
- end repeatend tellreturn
- on csvParse(nrow, adelim)
- -- replaces the commas in each row of the CSV with newlines
- -- returns columns of data return paragraphs of (do shell script "sed -E 's/,/\\'$'\\n/g' <<<" & nrow's quoted form)
- end csvParse
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement