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

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How are you handling the data revolution? We want your take on what's real, what's hype, and what's next in the world of data engineering.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • The Unreasonable Effectiveness of the Actor Model for Creating Agentic LLM Applications
  • Managing AWS Managed Microsoft Active Directory Objects With AWS Lambda Functions
  • Why and How To Integrate Elastic APM in Apache JMeter
  • Multiplatform Directory Bookmarks on the Command Line

Trending

  • How You Clear Your HTML5 Canvas Matters
  • Top Trends for Data Streaming With Apache Kafka and Flink
  • Build Your Private Cloud at Home
  • Design Guards: The Missing Layer in Your Code Quality Strategy
  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
7.8K 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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • The Unreasonable Effectiveness of the Actor Model for Creating Agentic LLM Applications
  • Managing AWS Managed Microsoft Active Directory Objects With AWS Lambda Functions
  • Why and How To Integrate Elastic APM in Apache JMeter
  • Multiplatform Directory Bookmarks on the Command Line

Partner Resources

×

Comments

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: