• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Copy files with Preserving Timestamp

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I developed a Program to use Windows native commands from the Java to Copy Folders and files from one location to other location. Is there any way that I can preserve the Original file stamps for the files copied

Thanks
Srinivas
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am assuming you are making a system call to the windows "copy" command. my ten seconds of googling would indicate that no, it is not possible. the windows copy command seems to not support this option.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to implement file copying by executing native Windows copy commands from Java.

Java has its own built-in methods to copy files, which are cross-platform (they work on any operating system that supports them, not just Windows). The class java.nio.file.Files contains a number of copy() methods, one of which takes two java.nio.Path objects and zero or more java.nio.file.CopyOption objects. When you specify CopyOption.COPY_ATTRIBUTES, Java will attempt to copy file attributes from the source to the destination file, including the last modified time of the file.

See the API documentation of Files.copy(Path, Path, CopyOption...)
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately windows haven't come up with a solution regarding this issue but there are several programs which claim to be able to preserve the creation date of files and obviously RoboCopy is an option to resolve the above issue. I've been a user of that myself, but has now been inconvenienced by several arbitrary error messages. Although I used to repeat the steps again and again taking care of everything, but I still used to get the same error. So the best among those few programs which surely will do the trick is GS RichCopy 360. The software provides allot of other features like e-mail notification when job is done, scheduling your copy etc. Its very robust and reliable. I've been using it myself from a long time. You must give it a try. Hope this might help.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I don't know whether the OP is still looking for a solution, but that sounds promising.
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic