From ecf5a2424748441e0bbfa44bf2a6eb75176d0e9f Mon Sep 17 00:00:00 2001 From: ChangHangeol Date: Sat, 7 Jun 2025 16:52:14 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EC=97=AC=EB=9F=AC=20csv=20file?= =?UTF-8?q?=EC=9D=84=20=ED=95=9C=EB=B2=88=EC=97=90=20=EC=9D=BD=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.ts | 16 +++++++++++++++- src/CSVFilemanager.ts | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/main.ts b/main.ts index 81975f6..a5c90d8 100644 --- a/main.ts +++ b/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 => { + const file = app.vault.getAbstractFileByPath(fileName); + if(file) { + return true; + } else { + return false; + } + } + async onload() { // await this.loadSettings(); diff --git a/src/CSVFilemanager.ts b/src/CSVFilemanager.ts index 3c70e23..383f184 100644 --- a/src/CSVFilemanager.ts +++ b/src/CSVFilemanager.ts @@ -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 => { const vault = app.vault;