CSV File collate data script

Hi,

I was wondering if anybody could help with the following automation task,

I have a folder full of individual csv files which I need to extract the data from each sheet and put into one csv file on one sheet. The format for each csv file is the same if it is possible to omit row one out of each csv file copy that would be really handy but not essential.

Any help would be greatly appreciated

thanks

Hi,

try this, you will be prompted to choose the source files and to define a file name and location for the destination file.
If the CSV files are UTF-8 encoded uncomment the two lines containing «class utf8» and comment out read and write lines above respectively.


set sourceFiles to (choose file with prompt "Choose source files" of type "csv" with multiple selections allowed)
set destinationFile to choose file name with prompt "Enter destination file name"
try
	set fileReference to open for access destinationFile with write permission
	repeat with i from 1 to count sourceFiles
		set aFile to item i of sourceFiles
		set csvData to (read aFile)
		-- set csvData to (read aFile as «class utf8»)
		set secondParagraph to paragraph 2 of csvData
		set offsetOfSecondParagraph to offset of secondParagraph in csvData
		if i = 1 then
			set dataToWrite to csvData
		else
			set dataToWrite to text offsetOfSecondParagraph thru -1 of csvData
		end if
		write dataToWrite to fileReference starting at eof
		-- write dataToWrite to fileReference as «class utf8» starting at eof
	end repeat
	close access fileReference
on error
	try
		close access destinationFile
	end try
end try


Cheers StefanK that has helped me massively really appreciate it :smiley: