Copying files using ant


















Another ant task is Copydir. The key part here is to include the name of the directory you want to copy after the dest directory. The sub-directories and files will be copied automatically.

This code should copy the folder as well as its contents. It also uses the basename task to avoid having to do any manual path parsing. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to copy a directory using Ant Ask Question. Asked 12 years, 2 months ago. Active 1 year, 8 months ago. Viewed 93k times. How can I copy the entire tree?

Sounds like you want to do a recursive copy. And that's the solution that Omnipresent gave. More people may find this question if the word "recursive" appeared in the question. Add a comment. Active Oldest Votes. Recursive copy done. Omnipresent Omnipresent Copies not a did but it's content. Note that there should be no blank line s or whitespace s before the xml declaration.

The default target for the build script. A project may contain any number of targets. This attribute specifies which target should be considered as the default. A target is a collection of tasks that you want to run as one unit. In our example, we have a simple target to provide an informational message to the user. Targets can have dependencies on other targets. For example, a deploy target may have a dependency on the package target, the package target may have a dependency on the compile target and so forth.

Dependencies are denoted using the depends attribute. Adds the target to the dependency list of the specified Extension Point. An Extension Point is similar to a target, but it does not have any tasks. Files : This class consists exclusively of static methods that operate on files, directories, or other types of files.

Improve this answer. Community Bot 1 1 1 silver badge. That is Java not Groovy. So that is not the answer then. See this link for groovy answer. The link basically shows other answers of this question, and quoting it: "Note that this can be potentially slow and memory hungry, as this code loads the entire file to memory before copying". That is quite an issue, so I will say again that it is better to delegate to the underlying file system although there are other groovier solutions.

Anyway, thanks for commenting on your downvote. How do you create a Path from a String? If you are doing this in code, just use something like: new File 'copy. While this is nice and simple, it loads the whole file into memory, which will fail for large files. There are ways to stream it as well How is this different from the accepted answer? And is there even a method that accepts Path and File? File class has that method for a reason. This way is using such method which is not being used by the accepted answer.

In Groovy, File is already included while Path needs to be imported. If you mainly use Path, then the accepted answer is better, but if you use File this ways is more convenient IMHO, but you may think otherwise. Sahil Chhabra Sahil Chhabra 8, 4 4 gold badges 61 61 silver badges 57 57 bronze badges. It's useful if you need to transform the file on the way: change encoding for example 4th looks overcomplicated to me You mean NIO2 introduced in Java 7.

Nayana Adassuriya Nayana Adassuriya Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.



0コメント

  • 1000 / 1000