Este código en Harbour te permite crear un unico fichero a partir de todos los ficheros de tu proyecto y asi poder dárselo a distintas IAs para preguntar acerca de tu proyecto:
onefile.prg
// Standalone consolidation script for your project sources
#include "directry.ch"
#define CRLF chr(13) + chr(10)
#define FW_ROOT "c:\your_project_folder\"
#define FW_TARGET ( FW_ROOT + "onefile.txt" )
#define FW_LOG ( FW_ROOT + "onefile.log" )
function Main()
local cRoot := FW_ROOT
local cTarget := FW_TARGET
local cLog := FW_LOG
local aDirs := {}
local aAll := Directory( cRoot + "*", "D" )
local aItem
local nHandle, nLog
local cDir
for each aItem in aAll
if "D" $ aItem[ 5 ] .and. ! ( aItem[ 1 ] == "." .or. aItem[ 1 ] == ".." .or. aItem[ 1 ] == ".git" )
aAdd( aDirs, aItem[ 1 ] )
endif
next
? "PROCESS START: OneFile Consolidation"
nHandle := fCreate( cTarget )
if nHandle == -1
? "Error: Could not create target file: ", cTarget
return nil
endif
nLog := fCreate( cLog )
fWrite( nLog, "Starting full project consolidation with exclusions..." + CRLF )
fWrite( nHandle, "FILE STRUCTURE TREE" + CRLF )
fWrite( nHandle, "========================================" + CRLF )
WriteTree( cRoot, 0, nHandle )
fWrite( nHandle, CRLF + "FILE CONTENTS" + CRLF )
fWrite( nHandle, "========================================" + CRLF + CRLF )
for each cDir in aDirs
ProcessDir( cRoot + cDir, nHandle, nLog, cRoot )
next
fClose( nHandle )
fWrite( nLog, "Done." + CRLF )
fClose( nLog )
? "Done. File created: ", cTarget
return nil
function WriteTree( cPath, nIndent, nHandle )
local aFiles := Directory( cPath + "\*", "D" )
local aFile
local cIndent := Replicate( " ", nIndent )
for each aFile in aFiles
if aFile[ 1 ] == "." .or. aFile[ 1 ] == ".."
loop
endif
if "D" $ aFile[ 5 ]
fWrite( nHandle, cIndent + "[+] " + aFile[ 1 ] + CRLF )
WriteTree( cPath + "\" + aFile[ 1 ], nIndent + 1, nHandle )
else
fWrite( nHandle, cIndent + " " + aFile[ 1 ] + CRLF )
endif
next
return nil
function ProcessDir( cPath, nHandle, nLog, cRoot )
local aFiles := Directory( cPath + "\*", "D" )
local aFile
local cContent, aLines, nLine, cRelativeName
for each aFile in aFiles
if aFile[ 1 ] == "." .or. aFile[ 1 ] == ".."
loop
endif
if "D" $ aFile[ 5 ]
ProcessDir( cPath + "\" + aFile[ 1 ], nHandle, nLog, cRoot )
else
cRelativeName := SubStr( cPath + "\" + aFile[ 1 ], Len( cRoot ) + 1 )
if ShouldSkip( cPath + "\" + aFile[ 1 ], aFile[ 1 ] )
fWrite( nLog, "Skipping: " + cRelativeName + CRLF )
loop
endif
fWrite( nLog, "Processing: " + cRelativeName + CRLF )
fWrite( nHandle, "FILE: " + cRelativeName + CRLF )
fWrite( nHandle, "----------------------------------------" + CRLF )
cContent := MemoRead( cPath + "\" + aFile[ 1 ] )
aLines := hb_ATokens( cContent, CRLF )
for nLine := 1 to Len( aLines )
fWrite( nHandle, StrZero( nLine, 5 ) + ": " + aLines[ nLine ] + CRLF )
next
fWrite( nHandle, CRLF + "========================================" + CRLF + CRLF )
endif
next
return nil
function ShouldSkip( cFile, cName )
local cExt := Lower( SubStr( cName, RAt( ".", cName ) ) )
local aExcl := { ".map", ".doc", ".docx", ".pdf", ".ps1" }
if AScan( aExcl, cExt ) > 0
return .t.
endif
return IsBinary( cFile )
function IsBinary( cFile )
local nH := fOpen( cFile )
local cBuf := space( 1024 )
local nLen
local lBinary := .f.
local n
if nH != -1
nLen := fRead( nH, @cBuf, 1024 )
for n := 1 to nLen
if asc( substr( cBuf, n, 1 ) ) == 0
lBinary := .t.
exit
endif
next
fClose( nH )
endif
return lBinary