I have a folder having Cobol source code, and I am trying to extract comments from the file. Below code is working for me and extracting comments into a single file.
$files = Get-Childitem -Path 'C:\Users\TextFiles' -File -Recurse -ErrorAction SilentlyContinue
$result = foreach($file in $files)
{
'{0} | {1} ' -f $file.DirectoryName, $file.BaseName
$content = Get-Content $file.FullName
$temp = @()
foreach ($line in $content) {
if ($line[6] -eq '*' ) {
$line
}}
}
$result | Out-File 'C:\Users\Desktop\\Comments.txt'
But I need to extract comment for each file separately. Any help would be much appreciated.
I am new to Powershell sso I might be way off course with my logic and understanding of Powershell, please can you point me in the general direction and I'll go and do some more reading. Thanks in advance!