diff --git a/README.md b/README.md index 9f63b7d..b0973d1 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,10 @@ This will create a file named "file-for-ai.txt" in your current directory with t You can also use a glob pattern: ``` bash -file-for-ai *.txt +file-for-ai ./**/*.txt ``` -This will create a file named "file-for-ai.txt" in your current directory with the contents of all text files matching the pattern. +This will create a file named "file-for-ai.txt" in your current directory with the contents of all txt files in the current directory and its subdirectories. To specify a custom output file name: diff --git a/go.mod b/go.mod index 8507b79..dbb99b1 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.11.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect + github.com/yargevad/filepathx v1.0.0 // indirect golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect golang.org/x/text v0.3.7 // indirect diff --git a/go.sum b/go.sum index c07b813..effa015 100644 --- a/go.sum +++ b/go.sum @@ -305,6 +305,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5FYc= +github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/main.go b/main.go index c2f7d9f..26e76f8 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/denormal/go-gitignore" + "github.com/yargevad/filepathx" "github.com/num30/config" "github.com/pkoukk/tiktoken-go" @@ -35,7 +36,7 @@ func main() { fmt.Println("Usage: file-for-ai --output [output file]") fmt.Println("\nExamples:") fmt.Println(" file-for-ai /path/to/directory") - fmt.Println(" file-for-ai '*.txt'") + fmt.Println(" file-for-ai './*.txt'") fmt.Println(" file-for-ai /path/to/directory --output custom-output.txt") fmt.Println("\nFor more information, visit https://github.com/num30/file-for-ai?tab=readme-ov-file#file-for-ai") os.Exit(1) @@ -45,11 +46,6 @@ func main() { outputFileName := conf.OutputFile - if _, err := os.Stat(outputFileName); !os.IsNotExist(err) { - fmt.Printf("Output file %s already exists\n", outputFileName) - os.Exit(1) - } - outputFile, err := os.Create(outputFileName) if err != nil { fmt.Println("Error creating output file:", err) @@ -87,7 +83,7 @@ func main() { return processFile(inputPath, path, info, outputFile, tkm, &tokens, outputFileName) }) } else { - files, err := filepath.Glob(inputPath) + files, err := filepathx.Glob(inputPath) if err != nil { fmt.Println("Error parsing glob pattern:", err) os.Exit(1)