commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mario Ivankovits <ma...@ops.co.at>
Subject Re: [VFS] fileObject.copyFrom ?
Date Mon, 05 Sep 2005 18:52:39 GMT
nice@email.dk wrote:
>And what a great tool VFS is :-) Just having some startup difficulties.
>  
Thanks!
>file = fsManager.resolveFile("/path/someDir");
>remDir.copyFrom(file, new AllFileSelector());
>
>Ok, the file I want to copy is the directory + content. Somehow it is only the
>content of the dir that is copied?? How can i do this?
>  
I am not sure if I understand you fully, but:

You do have a directory e.g.

/home/im/tmp/src
/home/im/tmp/src/file.txt
/home/im/tmp/src/dir/file2.txt

and your remDir is e.g. "/home/im/tmp/dest"

after the copyFrom you have
/home/im/tmp/dest
/home/im/tmp/dest/file.txt
/home/im/tmp/dest/dir/file2.txt

but you would like to have:
/home/im/tmp/dest/src
/home/im/tmp/dest/src/file.txt
/home/im/tmp/dest/src/dir/file2.txt

correct?


The following two code blocks will solve this:

---cut---
        final FileObject foIN = 
VFS.getManager().resolveFile("/home/im/tmp/src/");
        FileObject foOUT = 
VFS.getManager().resolveFile("/home/im/tmp/dst/");
        FileObject foOUT2 = foOUT.resolveFile(foIN.getName().getBaseName());
        foOUT2.copyFrom(foIN, new AllFileSelector());
---cut---

---cut---
        final FileObject foIN = 
VFS.getManager().resolveFile("/home/im/tmp/src");
        FileObject foOUT = VFS.getManager().resolveFile("/home/im/tmp/dst");
        foOUT.copyFrom(foIN.getParent(), new FileSelector()
        {
            public boolean includeFile(FileSelectInfo fileInfo) throws 
Exception
            {
                return 
foIN.getName().isDescendent(fileInfo.getFile().getName(), 
NameScope.DESCENDENT_OR_SELF);
            }

            public boolean traverseDescendents(FileSelectInfo fileInfo) 
throws Exception
            {
                return fileInfo.getDepth() == 0 || includeFile(fileInfo);
            }
        });
---cut---

Hope this helps!
---
Mario


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


Mime
View raw message