Объединение множества файлов в один

568
Liam McCann

В настоящее время у меня есть эта команда:

copy /b *.txt newfile.txt 

Но я хочу также включить все файлы с папками.

  • Как я могу это сделать? Возможно ли добавить это в Apache Ant?

Я также рассматриваю возможность сделать это для минимизации файлов JS.

  • Есть ли способ удалить строки?
  • Есть ли лучшая команда для использования, чем та, которую я сейчас использую?

ТЕКУЩИЙ КОД

<target name="concatenate" description="Concatenate all js files"> <concat destfile="build/application.js"> <fileset dir="js" includes="**/*.js" /> </concat> </target> <target name="compress" depends="concatenate" description="Compress application.js to application-min.js"> <apply executable="java" parallel="false"> <filelist dir="build" files="application.js" /> <arg line="-jar" /> <arg path="C:\yuicompressor-2.4.7\build\yuicompressor-2.4.7.jar" /> <srcfile /> <arg line="-o" /> <mapper type="glob" from="*.js" to="build/*-min.js" /> <targetfile /> </apply> </target> 
1
Какую ОС вы используете? EBGreen 11 лет назад 0
Windows 7 последняя Liam McCann 11 лет назад 0
Вы спрашиваете, есть ли лучшая команда. Если тот, который у вас есть, работает, я не уверен, что вы имеете в виду под лучше. Кроме того, какие линии вы бы хотели удалить? EBGreen 11 лет назад 0
Не удалит ли компрессор YUI ненужные пустые строки? Mechanical snail 11 лет назад 0

1 ответ на вопрос

0
amotzg

On a nix OS you can use:

 find | xargs cat | sed ':a;N;$!ba;s/\n/ /g' 

This will first find all files under the current folder, than concatenate them and than remove new line characters with sed script that adds lines to a register without the new line.

I suspect from the use of copy command that you are using Windows, you will have to find the windows equivalents to the nix commands.
find for example can be replaced with dir /s /b. type might be a fine replacment for cat. etc.

Or you can have a look in this answer https://stackoverflow.com/questions/127318/is-there-any-sed-like-utility-for-cmd-exe that explain how to use nix command tools on windows.

Похожие вопросы