• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

copying folder and all of its contents

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why reinvent the wheel? I'd simply use http://jakarta.apache.org/commons/io/api-release/org/apache/commons/io/FileUtils.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic