-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileBinder_Code
More file actions
31 lines (27 loc) Β· 1.58 KB
/
FileBinder_Code
File metadata and controls
31 lines (27 loc) Β· 1.58 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
# Set the root path to the current working directory
$rootPath = Get-Location
$currentDateTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$isoTimeStamp = (Get-Date).ToUniversalTime().ToString("yyyyMMddTHH.mm.ss") + "Z"
$prefix = "$isoTimeStamp-$((Get-Item $rootPath).Basename)"
$outputFile = "$rootPath\$prefix-all_files.txt"
# Clear the output file if it already exists
if (Test-Path $outputFile) {
Remove-Item $outputFile
}
# Initialize a variable to hold the total character count
$totalCharacterCount = 0
Get-ChildItem -Path $rootPath -Recurse -Include *.js, *.jsx, *.html, *.css, *.txt | Where-Object { $_.FullName -notmatch '\\node_modules\\' -and $_.FullName -notmatch '\\build\\' -and $_.FullName -notmatch '\\Archive\\' } | ForEach-Object {
$relativePath = $_.FullName.Substring($rootPath.Length + 1)
$fileContent = Get-Content $_.FullName -Raw
# Accumulate the character count for each file
$totalCharacterCount += $fileContent.Length
# Write the relative path and file name to the output file
Add-Content -Path $outputFile -Value ("`n`n--- $relativePath ---`n`n")
# Append the file content to the output file
Add-Content -Path $outputFile -Value $fileContent
# Add a newline after each file's content for separation
Add-Content -Path $outputFile -Value "`n"
}
# Write the filename, current date and time, and the total character count at the beginning of the file
$existingContent = Get-Content $outputFile -Raw
Set-Content $outputFile -Value ("Filename: $prefix`nGenerated on: $currentDateTime`nTotal Characters: $totalCharacterCount`n" + $existingContent)