Created
August 27, 2025 09:50
-
-
Save kuc-arc-f/b1db41459f6712675a589ce30d21491f to your computer and use it in GitHub Desktop.
obsidian search , example
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
| export const EXT_TIME = [ | |
| /* JS */ | |
| ".js", | |
| ".jsx", | |
| ".ts", | |
| ".tsx", | |
| ".json", | |
| ".css", | |
| ".htm", | |
| ".html", | |
| ".vue", | |
| ".svelte", | |
| /* py */ | |
| ".py", | |
| /* GO */ | |
| ".go", | |
| /* RUST */ | |
| ".rs", | |
| /* PHP */ | |
| ".php", | |
| ]; |
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
| import fs from "fs"; | |
| import path from "path"; | |
| import { EXT_TIME } from "./config.js"; | |
| const TARGET_PATH = "/path/Obsidian/vault/codevault" | |
| /** | |
| * | |
| * @param | |
| * | |
| * @return | |
| */ | |
| function getAllFiles(dirPath, arrayOfFiles = []) { | |
| const files = fs.readdirSync(dirPath); | |
| for (const file of files) { | |
| const fullPath = path.join(dirPath, file); | |
| if (fs.statSync(fullPath).isDirectory()) { | |
| // 再帰で探索 | |
| getAllFiles(fullPath, arrayOfFiles); | |
| } else { | |
| arrayOfFiles.push(fullPath); | |
| } | |
| } | |
| return arrayOfFiles; | |
| } | |
| /** | |
| * | |
| * @param | |
| * | |
| * @return true: OK, false: NG | |
| */ | |
| const validExtention = function(ext){ | |
| let ret = false; | |
| ret = EXT_TIME.includes(ext); | |
| // console.log(ret); | |
| return ret; | |
| } | |
| /** | |
| * | |
| * @param | |
| * | |
| * @return | |
| */ | |
| function main(){ | |
| try{ | |
| // 例: test フォルダ内の全ファイルパスを取得 TARGET_PATH | |
| const folderPath = path.resolve(TARGET_PATH); // 絶対パスに変換 | |
| const files = getAllFiles(folderPath); | |
| //console.log(files); | |
| for (const file of files) { | |
| let vdir = fs.statSync(file).isDirectory(); | |
| if(!vdir){ | |
| console.log("vdir=", file); | |
| let pathObject = path.parse(file); | |
| let fileName = pathObject.base; | |
| //console.log(fileName); | |
| let ext = pathObject.ext; | |
| console.log("ext=", ext); | |
| let vExt = validExtention(ext); | |
| console.log("vExt=", vExt); | |
| if(ext !== ".md" && vExt){ | |
| let targetDir = pathObject.dir; | |
| let targetFnm = targetDir + "\\" + fileName+ ".md"; | |
| console.log("chgname=", targetFnm); | |
| fs.renameSync(file, targetFnm); | |
| } | |
| } | |
| } | |
| }catch(e){ console.log(e);} | |
| } | |
| //console.log(EXT_TIME); | |
| main(); |
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
| { | |
| "name": "tool-1", | |
| "version": "1.0.0", | |
| "main": "index.js", | |
| "type":"module", | |
| "scripts": { | |
| "start": "node ./main.js", | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "keywords": [], | |
| "author": "", | |
| "license": "ISC", | |
| "description": "" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment