Complete list of source code in files .c and .h

9 views
Skip to first unread message
Message has been deleted

Richard.Williams.20

unread,
Sep 9, 2009, 4:06:17 PM9/9/09
to biterscripting

I was asked the following question (reworded).



> i have around several .c and .h files scattered
> in different folders,
> i want the text in all of the source files to be appended
> and form a single text file containing all the code.
> How can this be done ?


The following script will do that. Let's say the .c and .h files are
in folder C:/softwareproject (and in its subfolders at any level). We
want to create a .txt file containing all the code and put it into
file "C:/softwareproject/all.txt".

# Script projectfiles.txt


# Change directory to the project.
cd "C:/softwareproject"


# Empty out all.txt if it has "stuff" from pervious run.
echo "" > "C:/softwareproject/all.txt"


# Collect a list of .c and .h files.
var str list
# Get the list .c files into $list.
lf -rn "*.c" > $list
# Append the list of .h files.
lf -rn "*.h" >> $list


# Now we have a complete list. Go thru files one by one.
while ($list <> "")
do


# Get the next file from the list.
var str file ; lex "1" $list > $file


# Append the contents of this file to all.txt.
cat $file >> "C:/softwareproject/all.txt"


done
# End of script


We are using the -r (recursive) option of the lf (list files) command
so that C:/softwareproject as well as all its subfolders at any level
will be searched.


Save the script as C:/Scripts/projectfiles.txt. To run the script,
enter the following command in biterscripting.


script "C:/Scripts/projectfiles.txt"


This will create the file "C:/softwareproject/all.txt" containing all
the code. You can then open it with any text editor or print it.


MAKE SURE YOU CHANGE "C:/softwareproject" TO THE CORRECT PATH in the
script. Always enclose paths and file names in double quotes.


Richard

Reply all
Reply to author
Forward
0 new messages