[VFS] fileObject.copyFrom ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[VFS] fileObject.copyFrom ?

Nice-6
Hi all!

And what a great tool VFS is :-) Just having some startup difficulties.

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?

thanks

Jens

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [VFS] fileObject.copyFrom ?

Mario Ivankovits
[hidden email] 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [VFS] fileObject.copyFrom ?

Nice-6
In reply to this post by Nice-6
Yes you got it, and it works fine.... thanks a lot.

I guess I assumed that the FileObject returned was that actual src folder, so
it seemed strange that it did not appear when copying it to dest dir.

thanks again

Jens


Mario Ivankovits wrote:

> [hidden email] 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> .
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]