# How to get a file's real size?

**URL:** <https://users.rust-lang.org/t/how-to-get-a-files-real-size/70674>\
**Category:** help\
**Created:** [January 21, 2022, 6:53pm UTC](https://users.rust-lang.org/t/how-to-get-a-files-real-size/70674 "2022-01-21T18:53:10Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![ClementNerma](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/clementnerma/32/4086_2.png) [@ClementNerma](https://users.rust-lang.org/u/ClementNerma)\
**Post date:** [January 21, 2022, 7:53pm UTC](https://users.rust-lang.org/t/how-to-get-a-files-real-size/70674/14 "2022-01-21T19:53:47Z")

</div>

Ok so the reason it was returning wrong values was because I'm just plain stupid.

Basically I do something like:

```rust
WalkDir::new(source).into_iter().map(|item| item.metadata().unwrap().len())

```

Except I was writing this:

```rust
WalkDir::new(source).into_iter().map(|item| source.metadata().unwrap().len())

```

See the little `source` instead of `item` before `.metadata()`? The code compiled correctly but I was getting the size of the source directory, which is by convention a cluster's size 🤦‍♂️

So problem solved, thank you all for helping and sorry for wasting your time 🙏

---

_[View the full topic](https://users.rust-lang.org/t/how-to-get-a-files-real-size/70674)._
