Need to concatenate all of the javascript files in a directory and all of its sub-directories into one file.
Right now I have a very simple command in a batch file that concatenates all of the matching files in one directory into one file:
copy C:\javascripts\*.js concatenated.js
However, this only works for the one directory and not any of its sub-directories. How can I do this same thing and also include all of the matching files in the sub-directories?
Thanks so much!
From the command line you can use
for /r "c:\javascripts" %F in (*.js) do @type "%F" >>concatenated.js
You might want want to first delete any existing concatenated.js before you run the above command.
From a batch file the percents need to be doubled
@echo off
del concatenated.js
for /r "c:\javascripts" %%F in (*.js) do type "%%F" >>concatenated.js
EDIT
It is a bit more efficient to put parentheses around the entire statement and use a single overwrite redirection instead of append redirection with each iteration. It also eliminates the need to delete the file in the beginning.
>concat.js (for /r "c:\javascripts" %F in (*.js) do @type "%F")
or from batch
@echo off
>concat.js (for /r "c:\javascripts" %%F in (*.js) do type "%%F")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With