DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • The Self-Healing Directory: Architecting AI-Driven Security for Active Directory
  • Scaling Identity Governance Without Connectors: The LDAP Directory IGA Integration Pattern
  • Why Developers Should Pay Attention to Internal Directory Security
  • The Unreasonable Effectiveness of the Actor Model for Creating Agentic LLM Applications

Trending

  • Mobile App Development Trends and Best Practices
  • How AI Is Rewriting Full-Stack Java Systems: Practical Patterns with Spring Boot, Kafka and WebSockets
  • How to Build an Agentic AI SRE Co-Pilot for Incident Response
  • Reproducible Development Environments, One Command Away: Introducing CodingBooth
  1. DZone
  2. Coding
  3. Languages
  4. Groovy Goodness: Calculating Directory Size

Groovy Goodness: Calculating Directory Size

By 
Hubert Klein Ikkink user avatar
Hubert Klein Ikkink
·
Jan. 31, 13 · Interview
Likes (0)
Comment
Save
Tweet
Share
8.0K Views

Join the DZone community and get the full member experience.

Join For Free

Groovy 2.1 adds the method directorySize() to File objects. If the File object is a directory then the total size of all files is calculated. Notice this method will go recursively through all subdirectories so it might take some time before the method returns. If we invoke the method on a File object that is not a directory an IllegalArgumentException is thrown.

def sampleDir = new File('sample')
def sampleDirSize = sampleDir.directorySize()

println sampleDirSize // Outputs size in bytes, eg. 130615981

Using Groovy from the command-line we can easily get the directory size like this:

$ groovy -e "println new File('.').directorySize()"

Written with Groovy 2.1


 

Groovy (programming language) Directory

Published at DZone with permission of Hubert Klein Ikkink. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • The Self-Healing Directory: Architecting AI-Driven Security for Active Directory
  • Scaling Identity Governance Without Connectors: The LDAP Directory IGA Integration Pattern
  • Why Developers Should Pay Attention to Internal Directory Security
  • The Unreasonable Effectiveness of the Actor Model for Creating Agentic LLM Applications

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook