Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6037767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:07:20+00:00 2026-05-23T06:07:20+00:00

After a certain time interval(month) I want to delete the subfolders with content. Can

  • 0

After a certain time interval(month) I want to delete the subfolders with content. Can someone help me to achieve this. The following code shows errors related to Iterator.

// Create a ref for closure
def dir
def yesterday = ( new Date() ).time - 1000*60*60*24    

//definition Closure    
dir = {
  while(it.hasNext()){
    it.eachDirRecurse( dir )
      println("Dir: " + it.canonicalPath)
    if(it.lastModified() <= yesterday)  
      it.deleteDir()
  }
}

// Apply closure
dir( new File("H:\\soapUI\\Adres\\") )

This is the Exception:

Caught: groovy.lang.MissingMethodException: No signature of method: java.io.File.hasNext() is applicable for argument types: () values: []
  Possible solutions: inspect(), getText(), getText(java.lang.String), setText(java.lang.String), setText(java.lang.String, java.lang.String), hashCode()\
at test$_run_closure1.doCall(test.groovy:8)
    at test.run(test.groovy:19)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:07:21+00:00Added an answer on May 23, 2026 at 6:07 am

    There’s at least couple of errors in your code…

    • why do you do it.hasNext() on a File
    • you call it.eachDirRecurse which will recurse down the whole tree, but you then call it again for every directory in that tree…

    You are also going to have problems as you will remove a directory, but then eachDirRecurse will still try to walk down into that directory and throw a FileNotFoundException

    I think you’re going to have to not use eachDirRecurse

    Assuming you are on Groovy 1.8 (you don’t say), you can do something like this:

    import groovy.time.TimeCategory
    import static groovy.io.FileType.*
    
    def yesterday = use( TimeCategory ) { new Date() - 1.day }
    
    def deleteFoldersIn = { File f ->
      f.traverse( [ type:DIRECTORIES, postDir:{ d -> if( d.lastModified() < yesterday.time ) d.deleteDir() } ] ) { 
        println "Scanning $it"
      }
    }
    
    // Apply closure
    deleteFoldersIn( new File( 'H:\\soapUI\\Adres\\' ) )
    

    Here’s the documentation for TimeCategory, FileType and File.traverse()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I do the following response.sendRedirect(index.jsp); after a certain time interval from another
i want to to get location after certain time so i can define minimum
I want to show text one after the other on certain interval of time
How to unlock device when its locked after certain amount of time,programmatically? I want
I couldn't find a solution for this yet...hope someone can help me. I have
I want a program to stop executing for a certain amount of time. And
I have a mySql query which adds certain interval of time to datetime field.
I have a windows service that calls a page after a certain interval of
I have created a service which displays a status bar notification after certain time
I have $.post() code and I wanna to pass him after certain time, is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.