aberrant80
aberrant80

Reputation: 12997

Ant target to move directories out of another directory

What is the simplest way to move everything out of a target directory?

I have this basedir/parentdir/<subdir>. I have many different <subdir>. I need to move them out into the same level as parentdir so that it becomes basedir/<subdir>. Now, each <subdir> contains a deep tree of many other subdirectories and files, including empty subdirectories.

I've tried the following:

<move todir="basedir">
    <fileset dir="parentdir">
        <include name="**/*.*" />
    </fileset>
</move>

That failed to move the empty directories - meaning after the move, all the <subdir> are missing their empty subdirectories. "move" supposedly copies emptysubdirectories by default, so I tried the following next:

<move todir="basedir">
    <fileset dir="parentdir">
        <include name="**/*" />
        <include name="**/*.*" />
    </fileset>
</move>

While I did manage to move the empty subdirectories, the strange thing is that all the immediate subdirectories of all the <subdir> gets copied into basedir. Every <subdir> has src, test, and build. These are now sitting in basedir as well as in their original moved <subdir>.

I'm positive I'm doing something wrong but I don't know what. Am I approaching things the wrong way?

Upvotes: 11

Views: 13298

Answers (1)

Prabhu R
Prabhu R

Reputation: 14222

Try this

<project name="moveproject" basedir="." default="moveDirs">
<target name="moveDirs">
    <move todir="${basedir}" includeEmptyDirs="yes" verbose="true">
        <fileset dir="parentdir" >
            <include name="**/*" />
        </fileset>
    </move>
</target>
</project>

Upvotes: 12

Related Questions