Skip to content

Commit c31b75e

Browse files
authored
rename data files for easier dynamic loading in v9 docsite (#673)
1 parent 951f649 commit c31b75e

File tree

247 files changed

+58
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
// Directory path (change this to your target folder)
5+
const directoryPath = path.join(__dirname, '../src/data');
6+
7+
// Function to list and rename files
8+
function listAndRenameFiles(dirPath) {
9+
try {
10+
// Check if directory exists
11+
if (!fs.existsSync(dirPath)) {
12+
console.error(`❌ Directory not found: ${dirPath}`);
13+
return;
14+
}
15+
16+
// Read all files in the directory
17+
const files = fs.readdirSync(dirPath);
18+
19+
if (files.length === 0) {
20+
console.log('📂 No files found in the directory.');
21+
return;
22+
}
23+
24+
console.log('📄 Files found:');
25+
files.forEach((file, index) => {
26+
const oldPath = path.join(dirPath, file);
27+
28+
// Skip directories
29+
if (fs.statSync(oldPath).isDirectory()) {
30+
console.log(` Skipping folder: ${file}`);
31+
return;
32+
}
33+
34+
console.log(` ${file}`);
35+
36+
// Create a new file name (example: file_1.txt, file_2.txt, etc.)
37+
const parsed = path.parse(file);
38+
const ext = parsed.ext;
39+
const newName = `${parsed.name.split('_').slice(0,2).join('_')}${ext}`;
40+
const newPath = path.join(dirPath, newName);
41+
42+
// Rename the file
43+
try {
44+
fs.renameSync(oldPath, newPath);
45+
console.log(` ✅ Renamed to: ${newName}`);
46+
} catch (err) {
47+
console.error(` ❌ Error renaming ${file}:`, err.message);
48+
}
49+
});
50+
51+
console.log('✅ All files processed.');
52+
} catch (err) {
53+
console.error('❌ Error reading directory:', err.message);
54+
}
55+
}
56+
57+
// Run the function
58+
listAndRenameFiles(directoryPath);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)