You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Varman <re...@gmail.com> on 2009/09/24 07:36:11 UTC

Ant task to unzip files to a dynamic folder

Hi all,

I too have same requirements in which i want extract zip files to different
folders without using custom codes. This is the code am using. this extracts
all zip files to "destination_dir" and so files with same name gets
overwitten (i want to avoid this). For me each zip file has to be extracted
to different folder inside "destination_dir".

	   <unzip dest="destination_dir">
			<fileset dir="source_dir">
				<include name="**/*.zip"/>
			</fileset>
            </unzip>

Can you please give me the solution if you have? I saw a thread already
posted for this requirement but that was not answered.

-Arul
-- 
View this message in context: http://www.nabble.com/Ant-task-to-unzip-files-to-a-dynamic-folder-tp25531390p25531390.html
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: Ant task to unzip files to a dynamic folder

Posted by Andy Stevens <in...@googlemail.com>.
Varman wrote:
> Hi,
> 
> Great thanks..that works.
> But its not working in windows. For windows we have to give something like
> 
>       <propertyregex override="yes"
>       property="zipname"  input="@{file}"
>       regexp=".*\\([^\\]*)\.zip" replace="\1"/>
> 
> See the change in regexp. How can i make it generic for both linux and
> windows?

regexp=".*[\\/]([^\\/]*)\.zip"
perhaps?  Won't work on linux if you actually have a backslash in a 
filename, but how likely is that really?
Or you could use the pathconvert task first to force it into one 
particular form so you know which to use.  Or use the condition task 
with os nested elements to conditionally set some property with the 
appropriate regex and use that regexp="${platform.specific.regex}"
The possibilities are endless...


Andy
-- 
http://pseudoq.sourceforge.net/  open source java sudoku application


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


Re: Ant task to unzip files to a dynamic folder

Posted by Varman <re...@gmail.com>.
Hi,

Great thanks..that works.
But its not working in windows. For windows we have to give something like

      <propertyregex override="yes"
      property="zipname"  input="@{file}"
      regexp=".*\\([^\\]*)\.zip" replace="\1"/>

See the change in regexp. How can i make it generic for both linux and
windows?

-Arul


Andy Stevens-2 wrote:
> 
> 2009/9/24 Varman <re...@gmail.com>:
>> Hi all,
>>
>> I too have same requirements in which i want extract zip files to
>> different
>> folders without using custom codes. This is the code am using. this
>> extracts
>> all zip files to "destination_dir" and so files with same name gets
>> overwitten (i want to avoid this). For me each zip file has to be
>> extracted
>> to different folder inside "destination_dir".
>>
>>           <unzip dest="destination_dir">
>>                        <fileset dir="source_dir">
>>                                <include name="**/*.zip"/>
>>                        </fileset>
>>            </unzip>
>>
>> Can you please give me the solution if you have? I saw a thread already
>> posted for this requirement but that was not answered.
>>
>> -Arul
> 
> Have you tried the ant-contrib for or foreach tasks?
> http://ant-contrib.sourceforge.net/tasks/tasks/index.html
> Something like
> 
> <for param="file">
>   <path>
>                         <fileset dir="source_dir">
>                                 <include name="**/*.zip"/>
>                         </fileset>
>   </path>
>   <sequential>
>     <propertyregex override="yes"
>       property="zipname"  input="@{file}"
>       regexp=".*/([^/]*)\.zip" replace="\1"/>
>     <mkdir dir="destination_dir/${zipname}"/>
>            <unzip dest="destination_dir/${zipname}" src="@{file}"/>
>   </sequential>
> </for>
> 
> perhaps?
> 
> 
> Andy
> -- 
> http://pseudoq.sourceforge.net/  open source java sudoku solver
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Ant-task-to-unzip-files-to-a-dynamic-folder-tp25531390p25748081.html
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: Ant task to unzip files to a dynamic folder

Posted by Andy Stevens <in...@googlemail.com>.
2009/9/24 Varman <re...@gmail.com>:
> Hi all,
>
> I too have same requirements in which i want extract zip files to different
> folders without using custom codes. This is the code am using. this extracts
> all zip files to "destination_dir" and so files with same name gets
> overwitten (i want to avoid this). For me each zip file has to be extracted
> to different folder inside "destination_dir".
>
>           <unzip dest="destination_dir">
>                        <fileset dir="source_dir">
>                                <include name="**/*.zip"/>
>                        </fileset>
>            </unzip>
>
> Can you please give me the solution if you have? I saw a thread already
> posted for this requirement but that was not answered.
>
> -Arul

Have you tried the ant-contrib for or foreach tasks?
http://ant-contrib.sourceforge.net/tasks/tasks/index.html
Something like

<for param="file">
  <path>
                        <fileset dir="source_dir">
                                <include name="**/*.zip"/>
                        </fileset>
  </path>
  <sequential>
    <propertyregex override="yes"
      property="zipname"  input="@{file}"
      regexp=".*/([^/]*)\.zip" replace="\1"/>
    <mkdir dir="destination_dir/${zipname}"/>
           <unzip dest="destination_dir/${zipname}" src="@{file}"/>
  </sequential>
</for>

perhaps?


Andy
-- 
http://pseudoq.sourceforge.net/  open source java sudoku solver

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