my dog learned polymorphism*
The moose likes Ant, Maven and Other Build Tools and the fly likes Trying to list the directory contents in a <fileset> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Trying to list the directory contents in a <fileset>" Watch "Trying to list the directory contents in a <fileset>" New topic
Author

Trying to list the directory contents in a <fileset>

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
Hello,

I'm trying to get ant to (at first) list the directory contents using the ant <fileset> task.

Here's what I have so far...



Eventually, after I'm actually able to list all the files in the filedir, I'll want to call a Java program to compress them (remove whitespace and comments from JS and CSS files).

I've tried adding an Echo command, but get the error that nested commands aren't supported.

How do I actually print out the directory listing, file by file, inside a task that uses the Fileset task/tag?

Once I'm able to process each file, then presumably I could use the java task to call a jar file to actually do something with each file?

Thanks in advance.

- M
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

I do not know of any Ant task that will print out the contents of a fileset. But why bother doing that? Why not simply use the copy task with your fileset and a filterchain using the deletecharacters, striplinebreaks, etc.


JBoss In Action
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1753
    
    7

You could use the <pathconvert> task, as is explained in this weblog.
It demonstrates how to convert a <path> definition to a pretty printable string, but the same approach should work for a <fileset>, since <pathconvert>'s refid attribute accepts a reference to either a <path>, <fileset>, <dirset>, or <filelist> according to the documentation.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
What I'm actually trying to do is this...

During the build task, I want to compress the JavaScript and CSS using the Yahoo tools.

Our javascript and css folders in the Java project (Eclipse) have about 10 files each.

And, the added complication is that the compression utility only takes one file at a time, no wildcards.

Is there a better way to process directories so that I call a compression utility with a javascript file as input and write the compressed output to another folder?

A batch file and an "Exec" sounds like it wouldn't be cross-platform.

Ideas would be appreciated.

Thanks again!!!

- M
 
Consider Paul's rocket mass heater.
 
subject: Trying to list the directory contents in a <fileset>
 
Similar Threads
Ant replace task problem
Ant - List Files in the current directory
Including a jar within a jar
How to use fileset for classpath javac argument in ANT?
includesfile help