mirror of
https://github.com/hangeol-chang/obsidian-csv-allinone.git
synced 2026-07-22 05:37:25 +00:00
[FEAT] 여러 csv file을 한번에 읽는 기능 추가
This commit is contained in:
parent
dc8a357a30
commit
ecf5a24247
2 changed files with 37 additions and 1 deletions
16
main.ts
16
main.ts
|
|
@ -4,7 +4,7 @@ import {
|
|||
} from 'obsidian';
|
||||
|
||||
import { createCSVInputModal_, createCSVTableView_ } from './src/CSVPlugin';
|
||||
import { readCSV_, saveCSV_} from 'src/CSVFilemanager';
|
||||
import { readCSV_, saveCSV_, readCSVs_ } from 'src/CSVFilemanager';
|
||||
import { CSVRow, CSVTable, Header } from './src/types'
|
||||
import CSVExplorerModal, { getCSVFileStructure } from 'src/CSVExplorer';
|
||||
import CSVCreateModal, { createCSVFile_ } from 'src/CSVCreator';
|
||||
|
|
@ -28,6 +28,11 @@ export default class CSVPlugin extends Plugin {
|
|||
return saveCSV_(app, fileName, table);
|
||||
}
|
||||
|
||||
readCSVs = async (app: App, filePath: string, filter: string): Promise< { key: string; value: CSVTable }[] | null> => {
|
||||
// filter의 정규식에 맞는 파일들을 읽어와서 return;
|
||||
return readCSVs_(app, filePath, filter);
|
||||
}
|
||||
|
||||
addRow = async (app: App, fileName: string, rows: CSVRow[]) => {
|
||||
// readCSV_로 읽어서, rows 추가 후 saveCSV_로 저장.
|
||||
const table = await readCSV_(app, fileName);
|
||||
|
|
@ -47,6 +52,15 @@ export default class CSVPlugin extends Plugin {
|
|||
createCSVFile_(this.app, filename, columnData);
|
||||
}
|
||||
|
||||
fileExists = async (app: App, fileName: string): Promise<boolean> => {
|
||||
const file = app.vault.getAbstractFileByPath(fileName);
|
||||
if(file) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async onload() {
|
||||
// await this.loadSettings();
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,28 @@ export const saveCSV_ = async (app: App, fileName: string, table: CSVTable): Pro
|
|||
return;
|
||||
}
|
||||
|
||||
export const readCSVs_ = async (app: App, filePath: string, filter: string): Promise<{ key: string; value: CSVTable }[] | null> => {
|
||||
// filter의 정규식에 맞는 파일들을 읽어와서 return;
|
||||
const vault = app.vault;
|
||||
const files = vault.getFiles();
|
||||
console.log(`readCSVs_ : ${filePath}, filter: ${filter}`);
|
||||
console.log(files);
|
||||
const csvFiles: { key: string; value: CSVTable }[] = [];
|
||||
|
||||
for(const file of files) {
|
||||
if(file.path.startsWith(filePath) && file.path.endsWith('.csv') && file.name.match(filter)) {
|
||||
const table = await readCSV_(app, file.path);
|
||||
if(table) csvFiles.push({ key: file.name, value: table });
|
||||
}
|
||||
}
|
||||
|
||||
if(csvFiles.length > 0) {
|
||||
return csvFiles;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// save, load
|
||||
const saveFile = async (app: App, fileName: string, content: string): Promise<void> => {
|
||||
const vault = app.vault;
|
||||
|
|
|
|||
Loading…
Reference in a new issue