• 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
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

run native move command in Java

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

I have to zip all the files in a folder which has the timestamp more than 90days, for this i want to move all the files to a filder which ever has > 90days timestamp, to achive this i have used IO package, but the original time stamps of the files are changing to current date, to avoid this i started writing code in native "move" command, like below:



I am getting the below error, please help:

java.io.IOException: Cannot run program "move": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at com.ssga.jar.job.Sample.main(Sample.java:25)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
 
Bartender
Posts: 7488
171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There may be other problems, but for starters, use Runtime.exec(String[]), not Runtime.exec(String).
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried with String array too.
String st[] = {"move","sourcefodler","destinationfolder"};
Runtime.getRuntime().exec(st);

This also gives the same error :-(
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "move" command is part of the cmd.exe Windows shell interpreter. It is not a standalone application. You'd therefore need to execute the following command line:

cmd /c move file1 file2

Also note that your files contain spaces and you'd need to enclose them in double quotes. Furthermore, you need to read this famous article before you write code to execute an external program.

All in all, this is a lot of work to do an operation which is naturally supported by Java (see File.renameTo()). Of course, if you're moving across drives, that would be different, but there are still libraries like Apache Commons which I'd prefer to do this kind of job.
 
Sheriff
Posts: 17489
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem might be the spaces in "Documents and Settings". Try putting quotes around the file paths. And change your variable names while you're at it to make your code cleaner: para and para1 are not very descriptive


Better:

Or:


Pick your poison

Edit: Of course, there's all that Martin said above (posted while I was crafting this reply )
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic