aspose file tools*
The moose likes Java in General and the fly likes copying folder and all of its contents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "copying folder and all of its contents" Watch "copying folder and all of its contents" New topic
Author

copying folder and all of its contents

Mark Hughes
Ranch Hand

Joined: Jul 14, 2006
Posts: 146
Hey Guys,
I came across code to copy a file, simple enough



but does anyone know a similar method that would work for a whole folder and the folder contents?

Regards

Mark
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
It's pretty easy to write. Look into File.list and try something like

Now if your folder contains subfolders, you'll have to add a bit

Are you comfortable with that kind of recursion? Is that enough to go on?
[ November 09, 2006: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Mark Hughes
Ranch Hand

Joined: Jul 14, 2006
Posts: 146
sorry guys i forgot to put in the copy method,

but anyway i came across this code for copying a directory which works great



thanks

mark
Mark Hughes
Ranch Hand

Joined: Jul 14, 2006
Posts: 146
thanks stan,

i like the way you broke it down, makes alot of sense seeing it in that form rather than a bunch of code.

Cheers mark
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I frequently scribble that kind of psuedo code out to start a problem. What's fun is to translate to code line per line. I haven't compiled or checked this but consider ...

That's pretty near one-to-one with the sketch from before. Your logic is actually better because it allows the first "source" argument to be a file or directory. For fun try to make it this expressive and keep that feature.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Why reinvent the wheel? I'd simply use http://jakarta.apache.org/commons/io/api-release/org/apache/commons/io/FileUtils.html


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: copying folder and all of its contents
 
Similar Threads
dowloading file from a server problem
Copying of column
Writing file from Unix to a Windows File Server
Display the contents of folder when the link is clicked
Exclude of folder from being copied!?