Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete files in a directory which are copied from another directory?

Tags:

ant

I have two directories, say, A and B. A has several files: a1, a2, a3. B also has several files: b1, b2. First, I use the following ant tasks to copy all the files from B to A.

<copy todir="A" verbose="true">
    <fileset dir="B" includes="*"/>
</copy>

Then I want to undo the steps, i.e. delete the files in A which are copied from B, namely b1 and b2. How can I achieve the goals?

NOTE: the file names in the example are just used for us to understand the problem. I do not know the exact file names in the two directories.

like image 939
adarliu Avatar asked Apr 26 '11 01:04

adarliu


People also ask

How do I delete a file that was copied?

Type del "* - Copy. *" and press Enter. That command erases (permanently!) all files whose titles end with - Copy .

How do you remove a directory which contains files?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

How do you delete all files in a directory without deleting the directory?

Using the -r flag to deleting a non-empty directory. If you do not want a prompt before deleting the directory and its contents, use the -rf flag. This will remove everything inside the directory, including the directory itself, without any confirmation.


1 Answers

You should use a Selector to populate the FileSet of those files you want to delete. Try the Present Selector. Here's a target to complement your example:

<target name="copy" >
<copy todir="A" verbose="true">
    <fileset dir="B" includes="*"/>
</copy>
</target>

<target name="uncopy" >
<delete verbose="true">
    <fileset dir="A" >
        <present present="both" targetdir="B"/>
    </fileset>
</delete>
</target>
like image 162
DoctorRuss Avatar answered Nov 02 '22 23:11

DoctorRuss