Applescript, CSV, and file moving
Hey everyone. I don't know to much about Apple's since I was in the windows world for so long but I have a CSV file list of audio files that need to be renamed and moved to a new folder but I have a few thousand of them.
The file looks like such:
old_file1, new_file1
old_file2, new_file2
old_file3, new_file3
Can anyone help?
Comments
Wait everyone don't Dog pile this thread with answers now! I have figured it out...
-->set theTargetFolder to (path to desktop folder) as string
display dialog "please select the folder with the audio files"
set theTargetFolder to (choose folder) as string
set CopyFolderName to "renamed"
set theCopyFolder to theTargetFolder & CopyFolderName
--> set sFile to theTargetFolder & "file.csv"
display dialog "please select the CSV file"
set sFile to (choose file) as string
set csvData to read file sFile
set csvEntries to paragraphs of csvData
repeat with i from 1 to count csvEntries
set {orig_name, new_name} to parseCsvEntry(csvEntries's item i)
--> now, pass the parsed data to Entourage calendar event
--> if you need a valid date, just:
-- set fullDate to date (theDate & space & "2007" & space & theTime)
-->display dialog orig_name & ":" & new_name
--> set oldPath to duplicate new_name to theNewFolder
tell application "Finder"
if (exists folder theCopyFolder) then
(* do nothing *)
else
make new folder at theTargetFolder with properties {name:CopyFolderName}
end if
copy file (theTargetFolder & orig_name) to folder theCopyFolder
set the name of file (theCopyFolder & ":" & orig_name) to new_name
end tell
beep
end repeat
to parseCsvEntry(csvEntry)
set AppleScript's text item delimiters to ","
set {orig_name, new_name} to csvEntry's text items
set AppleScript's text item delimiters to {""}
return {orig_name, new_name}
end parseCsvEntry
tell application "Finder" to open folder theCopyFolder
display dialog "Renaming finished"