Vla*_*mir 7 ruby rake rakefile
我的目标是将模式指定的一组文件复制到目标目录.源目录中的文件可以包含子目录.
我试过了:
cp_r(Dir.glob('**/*.html'), @target_dir):
Run Code Online (Sandbox Code Playgroud)
和
cp_r(FileList['**/*.html'], @target_dir):
Run Code Online (Sandbox Code Playgroud)
但都没有工作.
它只适用于我做的事情:
cp_r(Dir['.'], @target_dir):
Run Code Online (Sandbox Code Playgroud)
但我只需复制*.html文件而不是其他任何东西.
我需要什么
cp --parents
Run Code Online (Sandbox Code Playgroud)
命令呢
有没有使用现有Ruby/Rake方法的建议?
更新看起来像使用Ant更容易做的事情,使用Ruby/Rake堆栈是不可能的 - 可能我需要查看其他内容.我不想编写自定义代码以使其在Ruby中工作.我只是想到Ruby/Rake作为适当的解决方案.
更新2这是我用Ant做的
<target name="buildeweb" description="Builds web site" depends="clean">
<mkdir dir="${build.dir.web}" />
<copy todir="${build.dir.web}" verbose="true">
<fileset dir="${source.dir.web}">
<include name="**/*.html" />
<include name="**/*.htm" />
</fileset>
</copy>
<chmod perm="a+x">
<fileset dir="${build.dir.web}">
<include name="**/*.html" />
<include name="**/*.htm" />
</fileset>
</chmod>
</target>
Run Code Online (Sandbox Code Playgroud)
如果你想要纯Ruby,你可以这样做(在标准库中的FileUtils的帮助下).
require 'fileutils'
Dir.glob('**/*.html').each do |file|
dir, filename = File.dirname(file), File.basename(file)
dest = File.join(@target_dir, dir)
FileUtils.mkdir_p(dest)
FileUtils.copy_file(file, File.join(dest,filename))
end
Run Code Online (Sandbox Code Playgroud)