Using basename to output the output file in java
I have a recursive directory structure containing some files foo
that I want to convert to files bar
using an XSLT 1.0 stylesheet. I have:
dir
|-- subdir
| |-- file1.foo
| |-- file2.foo
| |-- file3.foo
And I want to get:
dir
|-- subdir
| |-- file1.foo
| |-- file1.bar
| |-- file2.foo
| |-- file2.bar
| |-- file3.foo
| |-- file3.bar
To grab the base name of the files without the extension, I tried:
$ find . -type f -exec java -jar C:/saxon6-5-5/saxon.jar -o $(basename {} .foo).bar {} stylesheet.xsl \;
and
$ find . -type f -exec java -jar C:/saxon6-5-5/saxon.jar -o `basename {} .foo`.bar {} stylesheet.xsl \;
Both with the same result:
dir
|-- subdir
| |-- file1.foo
| |-- file1.foo.bar
| |-- file2.foo
| |-- file2.foo.bar
| |-- file3.foo
| |-- file3.foo.bar
The basename command doesn't seem to work. What could I be doing wrong?
source to share
The zsh approach is used here as it is marked as such.
for f in **/*.foo(.); print -- java ... -o $f:r.bar $f
Remove print --
when you are satisfied that it looks good.
(.)
only specifies files. :r
says it removes the extension .foo
. It is useful to remember path manipulators as "erth" for extension / removal / tail / head.
There's also zmv
an option -p
to call your java command.
source to share