You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Alx G <gl...@yahoo.co.uk> on 2007/10/02 13:09:59 UTC

how can I copy a directory of files to lower case equivalents?

Hi,

Does anyone know if there's anything in Ant that can copy files from a
directory to another directory but change all the file names to lower case?

e.g.

working/some_folder/etc/Blah.jpg => dist/some_folder/etc/blah.jpg
...
etc. for a whole load of files in various directories.

Perhaps there's something I can add to this?

<copy todir="${dist.dir}/images">
    <fileset dir="images"/>
</copy>

If there's nothing in Ant directly, I'm going to have to write a PHP script
that does the renaming but I'd prefer not to create more scripts.

Any help would be much appreciated.

Many Thanks!

-- 
View this message in context: http://www.nabble.com/how-can-I-copy-a-directory-of-files-to-lower-case-equivalents--tf4554266.html#a12996743
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: how can I copy a directory of files to lower case equivalents?

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

Hi,

-----Original Message-----
From: Steve Loughran [mailto:stevel@apache.org] 
Sent: Tuesday, October 02, 2007 2:36 PM
To: Ant Users List
Subject: Re: how can I copy a directory of files to lower case
equivalents?


/*
The ant-approved way would be a <copy> with an appropriate mapper listed

as a nested element. This gives copy the mapping from input filenames to

output names, lets it do the copying and dependency management as 
normal. You just provide the renaming logic .

I dont see one, but I do see in the manual the <scriptmapper> example, 
which (ant1.7+ only) would let you do what you want in a few lines


  <copy todir="${dist.dir}/images">
      <fileset dir="images"/>
     <scriptmapper language="javascript">
      self.addMappedName(source.toLowerCase());
    </scriptmapper>
  </copy>

If you are running on java6, javascript is built in -no need for extra 
JARs to get scripting working.

Case conversion does sound like a common use case...you could always 
write the java mapper and provide it with tests as an ant enhancement 
bugrep.
*/

i found an example with beanshell in the manual of ant 1.6.5.,
see my previous post.
But the problem is, with that snippet directorynames are lowercased too,
what if i want only filenames to lowercase but not the dirnames ?!

I tried to check that with your javascript mapper above, but it doesn't
run for me (ant 1.6.5)


Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: how can I copy a directory of files to lower case equivalents?

Posted by Alx G <gl...@yahoo.co.uk>.

Steve Loughran wrote:
> 
> Alx G wrote:
>> Hi,
>> 
>> Does anyone know if there's anything in Ant that can copy files from a
>> directory to another directory but change all the file names to lower
>> case?
>> 
>> e.g.
>> 
>> working/some_folder/etc/Blah.jpg => dist/some_folder/etc/blah.jpg
>> ...
>> etc. for a whole load of files in various directories.
>> 
>> Perhaps there's something I can add to this?
>> 
>> <copy todir="${dist.dir}/images">
>>     <fileset dir="images"/>
>> </copy>
>> 
>> If there's nothing in Ant directly, I'm going to have to write a PHP
>> script
>> that does the renaming but I'd prefer not to create more scripts.
>> 
>> Any help would be much appreciated.
>> 
>> Many Thanks!
>> 
> 
> The ant-approved way would be a <copy> with an appropriate mapper listed 
> as a nested element. This gives copy the mapping from input filenames to 
> output names, lets it do the copying and dependency management as 
> normal. You just provide the renaming logic .
> 
> I dont see one, but I do see in the manual the <scriptmapper> example, 
> which (ant1.7+ only) would let you do what you want in a few lines
> 
> 
>   <copy todir="${dist.dir}/images">
>       <fileset dir="images"/>
>      <scriptmapper language="javascript">
>       self.addMappedName(source.toLowerCase());
>     </scriptmapper>
>   </copy>
> 
> If you are running on java6, javascript is built in -no need for extra 
> JARs to get scripting working.
> 
> Case conversion does sound like a common use case...you could always 
> write the java mapper and provide it with tests as an ant enhancement 
> bugrep.
> 
> -steve
> 
> 
> 


Thanks a lot for all the suggestions. I've upgraded Ant to 1.7 as I like
this scriptmapper solution because it seems the simplest and most elegant.
I've been trying to get it working but so far no joy.

This is what I have:
...
<copy todir="${build.dir}/images/characters/icons">
	<fileset dir="images/characters/icons"/>
	<scriptmapper language="javascript"> 
		self.addMappedName(source.toLowerCase());				
	</scriptmapper>
</copy>
...

But it currently does nothing at all. If I take out the scriptmapper task
however it goes ahead and copies the 2000+ files (obviously not to lowercase
names as I would like). My files are of the form, Archery_Aim.gif etc. and
the uppercase characters can occur anywhere - I'm not sure if this is
relevant but I thought I'd mention it.

(I'm not bothered about directory names as they are all in lowercase
anyway).
-- 
View this message in context: http://www.nabble.com/how-can-I-copy-a-directory-of-files-to-lower-case-equivalents--tf4554266.html#a13133400
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: how can I copy a directory of files to lower case equivalents?

Posted by Steve Loughran <st...@apache.org>.
Alx G wrote:
> Hi,
> 
> Does anyone know if there's anything in Ant that can copy files from a
> directory to another directory but change all the file names to lower case?
> 
> e.g.
> 
> working/some_folder/etc/Blah.jpg => dist/some_folder/etc/blah.jpg
> ...
> etc. for a whole load of files in various directories.
> 
> Perhaps there's something I can add to this?
> 
> <copy todir="${dist.dir}/images">
>     <fileset dir="images"/>
> </copy>
> 
> If there's nothing in Ant directly, I'm going to have to write a PHP script
> that does the renaming but I'd prefer not to create more scripts.
> 
> Any help would be much appreciated.
> 
> Many Thanks!
> 

The ant-approved way would be a <copy> with an appropriate mapper listed 
as a nested element. This gives copy the mapping from input filenames to 
output names, lets it do the copying and dependency management as 
normal. You just provide the renaming logic .

I dont see one, but I do see in the manual the <scriptmapper> example, 
which (ant1.7+ only) would let you do what you want in a few lines


  <copy todir="${dist.dir}/images">
      <fileset dir="images"/>
     <scriptmapper language="javascript">
      self.addMappedName(source.toLowerCase());
    </scriptmapper>
  </copy>

If you are running on java6, javascript is built in -no need for extra 
JARs to get scripting working.

Case conversion does sound like a common use case...you could always 
write the java mapper and provide it with tests as an ant enhancement 
bugrep.

-steve

-- 
Steve Loughran                  http://www.1060.org/blogxter/publish/5
Author: Ant in Action           http://antbook.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: how can I copy a directory of files to lower case equivalents?

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
sorry forgot one line, the first post renames dirnames also,
so one has to use =

<script language="ruby">
<![CDATA[
require 'fileutils'
require 'find'

srcdir=$srcdir
destdir=$destdir
   
Dir.mkdir(destdir) unless File.exists?(destdir)
Dir.entries(srcdir).each do | i |
  if i !='.' && i !='..'
    FileUtils.cp_r Dir["#{srcdir}/**"], destdir
  end
end

Find.find(destdir) do |file|
  unless File.directory?(file)
    File.rename(file,file.downcase)
  end
end
 ]]>
 </script>


the line =
unless File.directory?(file) prevents dirnames from
renaming

Regards, Gilbert 



-----Original Message-----
From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de] 
Sent: Tuesday, October 02, 2007 2:12 PM
To: Ant Users List
Subject: RE: how can I copy a directory of files to lower case
equivalents?


Hi,

-----Original Message-----
From: Alx G [mailto:glubbah@yahoo.co.uk] 
Sent: Tuesday, October 02, 2007 1:10 PM
To: user@ant.apache.org
Subject: how can I copy a directory of files to lower case equivalents?

/*
Hi,

Does anyone know if there's anything in Ant that can copy files from a
directory to another directory but change all the file names to lower
case?
*/

here's a solution with <script> and ruby =

----------------snip----------------

<project name="bla" default="main" basedir=".">

<!-- // Properties -->
<property name="srcdir" value="Y:/test"/>
<property name="destdir" value="Y:/test_"/>
<!-- Properties // -->

<target name="depends">
  
<script language="ruby">
<![CDATA[
require 'fileutils'
require 'find'

srcdir=$srcdir
destdir=$destdir
   
Dir.mkdir(destdir) unless File.exists?(destdir)
Dir.entries(srcdir).each do | i |
  if i !='.' && i !='..'
    FileUtils.cp_r Dir["#{srcdir}/**"], destdir
  end
end

Find.find(destdir) do |file|
  File.rename(file,file.downcase)
end
 ]]>
 </script>

</target>

<target name="main" depends="depends">
<echo>
  
### Copy / Rename ###
src    = ${srcdir}
target = ${destdir}

</echo>
</target>
</project>

----------------snip----------------


Regards, Gilbert



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: how can I copy a directory of files to lower case equivalents?

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

Hi,

-----Original Message-----
From: Alx G [mailto:glubbah@yahoo.co.uk] 
Sent: Tuesday, October 02, 2007 1:10 PM
To: user@ant.apache.org
Subject: how can I copy a directory of files to lower case equivalents?

/*
Hi,

Does anyone know if there's anything in Ant that can copy files from a
directory to another directory but change all the file names to lower
case?
*/

here's a solution with <script> and ruby =

----------------snip----------------

<project name="bla" default="main" basedir=".">

<!-- // Properties -->
<property name="srcdir" value="Y:/test"/>
<property name="destdir" value="Y:/test_"/>
<!-- Properties // -->

<target name="depends">
  
<script language="ruby">
<![CDATA[
require 'fileutils'
require 'find'

srcdir=$srcdir
destdir=$destdir
   
Dir.mkdir(destdir) unless File.exists?(destdir)
Dir.entries(srcdir).each do | i |
  if i !='.' && i !='..'
    FileUtils.cp_r Dir["#{srcdir}/**"], destdir
  end
end

Find.find(destdir) do |file|
  File.rename(file,file.downcase)
end
 ]]>
 </script>

</target>

<target name="main" depends="depends">
<echo>
  
### Copy / Rename ###
src    = ${srcdir}
target = ${destdir}

</echo>
</target>
</project>

----------------snip----------------


Regards, Gilbert


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: how can I copy a directory of files to lower case equivalents?

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

Hi,


-----Original Message-----
From: Alx G [mailto:glubbah@yahoo.co.uk] 
Sent: Tuesday, October 02, 2007 1:10 PM
To: user@ant.apache.org
Subject: how can I copy a directory of files to lower case equivalents?

/*
Hi,

Does anyone know if there's anything in Ant that can copy files from a
directory to another directory but change all the file names to lower
case?
*/

also possible with filtermapper, taken from antmanual
slightly adapted =

<!-- // Properties -->
<property name="srcdir" value="Y:/test"/>
<property name="destdir" value="Y:/test_"/>
<!-- Properties // -->

<target name="depends">
  
<copy todir="${destdir}">
  <fileset dir="${srcdir}" includes="**/*.*"/>
  <filtermapper>
    <scriptfilter language="beanshell">
      self.setToken(self.getToken().toLowerCase());
    </scriptfilter>
  </filtermapper>
</copy>

but dir's get lowercase also

Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: how can I copy a directory of files to lower case equivalents?

Posted by david <da...@davidwbrown.name>.
Hello Alx, assuming you are on some type of NIX system (Windows doesn't car about case) the following is untested but you might want to twiddle around with it or this may get you a starting point in another direction:

<exec executable="/bin/mv">
    <arg value="${file}"/>
    <arg value="`echo ${file}|perl -ne 'chomp;print "$_" if (tr/A-Z/a-z/);'`"/>
</exec>

Alx G wrote ..
> 
> Hi,
> 
> Does anyone know if there's anything in Ant that can copy files from a
> directory to another directory but change all the file names to lower case?
> 
> e.g.
> 
> working/some_folder/etc/Blah.jpg => dist/some_folder/etc/blah.jpg
> ...
> etc. for a whole load of files in various directories.
> 
> Perhaps there's something I can add to this?
> 
> <copy todir="${dist.dir}/images">
>     <fileset dir="images"/>
> </copy>
> 
> If there's nothing in Ant directly, I'm going to have to write a PHP script
> that does the renaming but I'd prefer not to create more scripts.
> 
> Any help would be much appreciated.
> 
> Many Thanks!
> 
> -- 
> View this message in context: http://www.nabble.com/how-can-I-copy-a-directory-of-files-to-lower-case-equivalents--tf4554266.html#a12996743
> Sent from the Ant - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org