-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregs.js
41 lines (34 loc) · 1.08 KB
/
regs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const fs = require('fs');
const path = require('path');
const parse = require('csv-parser');
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const inputDir = 'legislativeaffairs';
const outputDir = 'new_legislativeaffairs';
const csvOutputPath = 'rename_tracking.csv';
const csvWriter = createCsvWriter({
path: csvOutputPath,
header: [
{ id: 'originalFilename', title: 'Original Filename' },
{ id: 'newFilename', title: 'New Filename' }
],
append: true // Append to existing CSV file
});
function sanitizeFilename(filename) {
return filename.replace(/[^\w\d.]/g, '-').toLowerCase();
}
fs.mkdirSync(outputDir, { recursive: true });
fs.readdirSync(inputDir).forEach((file) => {
if (file.endsWith('.pdf')) {
const originalFilename = file;
const newFilename = sanitizeFilename(file);
fs.copyFileSync(
path.join(inputDir, originalFilename),
path.join(outputDir, newFilename)
);
csvWriter.writeRecords([
{ originalFilename, newFilename }
]).then(() => {
console.log(`Processed: ${originalFilename}`);
});
}
});