Windows batch file - Concatenate all files in subdirectories

前端 未结 2 582
不知归路
不知归路 2020-12-24 14:47

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 t

相关标签:
2条回答
  • 2020-12-24 15:05

    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")
    
    0 讨论(0)
  • 2020-12-24 15:08

    I'm not aware of an approach to do that from a batch file, but you could use a tool like minify

    http://code.google.com/p/minify/

    to both combine JavaScript files and also minify them (e.g. by removing comments and unnecessary white space).

    There are quite a few similar tools for a variety of programming environments.

    0 讨论(0)
提交回复
热议问题