-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathInvoke-FilesToPrompt.ps1
More file actions
63 lines (48 loc) · 1.6 KB
/
Copy pathInvoke-FilesToPrompt.ps1
File metadata and controls
63 lines (48 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<#
.SYNOPSIS
Concatenate a directory full of files into a single prompt for use with LLMs
.DESCRIPTION
Takes one or more paths to files or directories and outputs every file, recursively, each one preceded with its filename like this:
path/to/file.ps1
----
Contents of file.ps1 goes here
---
path/to/file2.ps1
---
...
.PARAMETER Path
Specifies the path of the files to be processed.
.EXAMPLE
Invoke-FilesToPrompt -Path "C:\MyFiles"
This example invokes the Invoke-FilesToPrompt function to process files in the "C:\MyFiles" directory.
.EXAMPLE
Invoke-FilesToPrompt -Path "C:\MyFiles\*.md"
This example invokes the Invoke-FilesToPrompt function to process all Markdown files in the "C:\MyFiles" directory.
.EXAMPLE
Invoke-FilesToPrompt -Path "C:\MyFiles\*.md", "C:\MyOtherFiles\*.md"
This example invokes the Invoke-FilesToPrompt function to process all Markdown files in the "C:\MyFiles" directory.
.EXAMPLE
(Invoke-FilesToPrompt (dir . -r *.md))
This example recursively processes all Markdown files in the current directory.
#>
function Invoke-FilesToPrompt {
[CmdletBinding()]
param (
$Path
)
foreach ($item in $Path) {
if (!(Test-Path $item) ) {
Write-Host "$item does not exist." -ForegroundColor Red
continue
}
Write-Host "Processing $item" -ForegroundColor Green
foreach ($targetItem in Get-ChildItem $item -Recurse) {
$content = Get-Content $targetItem.FullName -raw
@"
$($targetItem.FullName)
---
$content
"@
}
}
}