![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Insert Header into Source Files What would be the best method to insert a header into existing source files? A simple method is to get-content (cat) the header and source file into a new file. I was hoping to be able to insert the header into the existing source files. .... Get-ChildItem -Recurse * | foreach { # check for directory if (!($_.PSIsContainer)) { # check for filename.extension format filename if (($_.Name.Split(".")).count -eq 2) { $basename,$extension = $_.Name.Split(".") # check for .c or .h files if ($extension -eq "c" -or $extension -eq "h") { get-content header.txt > $newpath + $_ get-content $_ >> $newpath + $_ } } } } .... |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Insert Header into Source Files You can combine Get-Content and Set-Content to write header.txt's content and the piped file's content 'back' to the piped file, but Set-Content will really overwrite the piped file with the modified content. Note the use of the optional -Encoding parameter, by default it's set to Unicode. Encoding acceptable values: Name Val ---- --- Unknown 0 String 1 Unicode 2 Byte 3 BigEndianUnicode 4 UTF8 5 UTF7 6 Ascii 7 In this example the new files' encoding will be UTF-8. First get the header's fully qualified path through Get-Item. Get child items and filter those files with a .c or .h extension. Get header content and the piped .c or .h file and overwrite the piped file through Set-Content. $hdr = (gi header.txt).fullname ls -r | ? {!$_.psIsContainer -and $_.extension -match '^\.[ch]$'} | % {sc $_.fullname (gc $hdr, $_.fullname) -en 5} -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| when insert a disc does not come to view files | Vista General | |||
| WLM insert scripts in code source | Live Mail | |||
| Possible to Read only Selected lines from multiple files into anotherfile deleting source files when processed? | PowerShell | |||
| CD Insert/Jewel Case Insert Maker ignored? | Vista music pictures video | |||
| Source files? | Vista General | |||