MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / readClipboardFilePathWindows

Function readClipboardFilePathWindows

cli/src/utils/clipboard-image.ts:453–477  ·  view source on GitHub ↗

* Read file path from clipboard when a file has been copied (Windows). * Returns the file path if found, null otherwise.

()

Source from the content-addressed store, hash-verified

451 * Returns the file path if found, null otherwise.
452 */
453function readClipboardFilePathWindows(): string | null {
454 try {
455 const script = `
456 Add-Type -AssemblyName System.Windows.Forms
457 $files = [System.Windows.Forms.Clipboard]::GetFileDropList()
458 if ($files.Count -gt 0) {
459 Write-Output $files[0]
460 }
461 `
462 const result = spawnSync('powershell', ['-STA', '-Command', script], {
463 encoding: 'utf-8',
464 timeout: 1000,
465 })
466
467 if (result.status === 0 && result.stdout) {
468 const filePath = result.stdout.trim()
469 if (filePath && existsSync(filePath)) {
470 return filePath
471 }
472 }
473 return null
474 } catch {
475 return null
476 }
477}
478
479/**
480 * Read file path from clipboard when a file has been copied (Linux).

Callers 1

readClipboardFilePathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected