Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Copying whole directories - odd behaviour

 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I'll fess up right away.

I don't see a "simple" way of doing it with java.io classes, so here is a small method I'm using:


My directory looks like:
/home/foo/templates/pattern
/home/foo/templates/pattern/images (empty directory)
/home/foo/templates/pattern/reports (empty directory)
/home/foo/templates/pattern/web/1 (that is actually a file '1' with no extension)

I'm trying to copy from
/home/foo/templates/pattern
into
/home/foo/instances/XX/

Where XX is a numbered instance of the pattern directory.

I'm invoking:
Files.copy("/home/foo/templates/pattern", "/home/foo/instances/XX");

What I'm getting is:
/home/foo/instances/XX/patterns/...
instead of
/home/foo/instances/XX/...

Where '...' represents the contents of the patterns directory.

I've also tried:
Files.copy("/home/foo/templates/pattern/*", "/home/foo/instances/XX");

I'm running Slack, so the Files.copy is properly using the unix commands (I've checked with logging statements).
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hrm..

reading man pages every so often might help.

... if /a is a directory, then `cp -r /a /b' will copy /a to /b/a and /a/x to /b/a/x in case a directory /b existed already, but it will copy /a to /b and /a/x to /b/x if there was no /b beforehand, while it will fail in case there was an ordinary file /b.

(I was getting caught by the first case. I was creating my 'XX' directory beforehand).
 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!