简体   繁体   中英

Adding headers on multiple file via batch file

I have a list of .c file where I want to add a header. The files are in a folder and the batch file should put an header to every .c file in that folder. I am inquisitive to know, how could we achieve this.

An example of the header I wanted to insert is as follows:

/////////////////////////////////////////////////////////////////////////////

Name: Tom Volvo Riddle
Roll No: 56/BS/352

////////////////////////////////////////////////////////////////////////////

Thanks,

You could use a batch script for loop to output the contents of the header file with each C source file. The output would be redirected into a new file.

Some renaming would be necessary to replace the original file with the new file containing the header.

To set up you would place your header text in the file header.txt . The batch file, header text file and C source should all be located in the same folder.

The original C files will be backed up in the process.

@echo off
for %%F in (*.c) do (
  echo Adding header text to C file %%F
  type header.txt "%%F" > "%%~nF.temp"
  rename "%%F" "%%~nF.bak"
  rename "%%~nF.temp" "%%F"
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM