• 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

Move portion of files from directory

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

I just want to know whether is there a way to get a portion of the total files from a directory so that I can move the portion of files to another directory. For example I have 1000 files in a directory and I want to move 200 of these files to another directory then will continue move another 200 and so on. The only way I can think of is using counting such as starting count from 1 till 200. Is there a way to make the hasnext() method to stop at 200 records when looking for files? Or is there another java method to do this.
Thanks and much appreciated.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a loop now that moves all files? What does it look like?

The cleaner way to terminate a looping routine is to do it in your while() or for() condition. If you have while( hasNext() ) now, how would you change it to stop at 200? A much uglier way is to "break" the loop. How would you make break happen after 200 files?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic