MCPcopy
hub / github.com/codeaashu/claude-code / findSimilarFile

Function findSimilarFile

src/utils/file.ts:178–207  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

176 */
177
178export function findSimilarFile(filePath: string): string | undefined {
179 const fs = getFsImplementation()
180 try {
181 const dir = dirname(filePath)
182 const fileBaseName = basename(filePath, extname(filePath))
183
184 // Get all files in the directory
185 const files = fs.readdirSync(dir)
186
187 // Find files with the same base name but different extension
188 const similarFiles = files.filter(
189 file =>
190 basename(file.name, extname(file.name)) === fileBaseName &&
191 join(dir, file.name) !== filePath,
192 )
193
194 // Return just the filename of the first match if found
195 const firstMatch = similarFiles[0]
196 if (firstMatch) {
197 return firstMatch.name
198 }
199 return undefined
200 } catch (error) {
201 // Missing dir (ENOENT) is expected; for other errors log and return undefined
202 if (!isENOENT(error)) {
203 logError(error)
204 }
205 return undefined
206 }
207}
208
209/**
210 * Marker included in file-not-found error messages that contain a cwd note.

Callers 2

callFunction · 0.85
validateInputFunction · 0.85

Calls 3

getFsImplementationFunction · 0.85
isENOENTFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected