Created
November 18, 2023 19:37
-
-
Save bpwebs/94c1aa7a76ee6b859ca83e072ecb6e72 to your computer and use it in GitHub Desktop.
Extract and combine first row of CSV files with Google Apps Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function extractFirstRowCsvWithFilename() { | |
const folder = DriveApp.getFolderById("1MBaI_rGJ6t_loANMAvGpDbr2MeHZwxnn"); | |
const files = folder.getFilesByType(MimeType.CSV); | |
let combinedData = []; | |
while (files.hasNext()) { | |
let file = files.next(); | |
let filename = file.getName(); | |
let csvData = Utilities.parseCsv(file.getBlob().getDataAsString()); | |
// Add the filename to the first column. | |
csvData[0].unshift(filename); | |
combinedData.push(csvData[0]); | |
} | |
folder.createFile("CombinedFirstRowWithFilename.csv", combinedData.join("\n"), MimeType.CSV); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment