1

I want to copy the newest file that is on a mapped network directory. I already have the network directory mapped to ${drive.letter} using NET USE.

<copy todir="${dest.dir}" overwrite="true">
    <first>
        <sort>
            <fileset dir="${drive.letter}\">
                <filename name="FileIWant-*.tar.gz" />
            </fileset>
            <date xmlns="antlib:org.apache.tools.ant.types.resources.comparators"/>
        </sort>
    </first>
</copy>

It takes an incredibly long time for this task to complete and am wondering why it takes so long and if I can speed it up. The network directory has 20K+ files in it. Does the sort task run first, then the fileset selector? Or is it just going to take awhile since it is going over the network?

The only other solution I can think of it to copy all FileIWant-*.tar.gz files locally then perform the sort but I am unsure if the copy will change the timestamp.

Spacebob
  • 267
  • 3
  • 13

2 Answers2

0

If you were using UNIX, I'd say to use to do this in a one line command line. Using ls/find, sort and head, this can be a one liner. Which has the benefits of not having a lot of extra work (Ant is busy building the fileset and doing lots of things one at a time over a network) and letting the OS optimize it.

I then searched how to do that in Windows and found this one liner. Same idea. I suspect it will be faster to do on the OS level. (although not as fast as having the files locally.)

Another alternative is to run dir and parse/sort that result. I can't imagine copying the files locally is going to be faster if it has to be done at runtime.

Community
  • 1
  • 1
Jeanne Boyarsky
  • 12,156
  • 2
  • 49
  • 59
0

I ended up writing a bat script to do this for me as it is much faster and I just call it from my Ant script.

echo Logging on to Server
net use %NetworkDir% 
if not errorlevel 0 goto error

pushd  %NetworkDir%
for /f "tokens=*" %%A in ('dir %FileIWant% /b /o:D') do (set sourceFile=%%A)
echo Copying %%A...
xcopy /V/F/Z/Y "%sourcefile%" "%copyTo%"
popd
Spacebob
  • 267
  • 3
  • 13