# Checking file size returns the same size

**URL:** <https://community.particle.io/t/checking-file-size-returns-the-same-size/58219>\
**Category:** Firmware\
**Tags:** boron\
**Created:** [October 27, 2020, 8:44pm UTC](https://community.particle.io/t/checking-file-size-returns-the-same-size/58219 "2020-10-27T20:44:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wasphax](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@wasphax](https://community.particle.io/u/wasphax)\
**Post date:** [October 27, 2020, 8:44pm UTC](https://community.particle.io/t/checking-file-size-returns-the-same-size/58219/1 "2020-10-27T20:44:28Z")

</div>

Hi all,  
I’m writing to the filesystem and want to check the file size using stat method ([https://docs.particle.io/reference/device-os/firmware/boron/#file-system-stat](https://docs.particle.io/reference/device-os/firmware/boron/#file-system-stat) )  
If the file doesnt exist, it returns the -1, but if it exists it seems to show the same size of the file: 1591.  
Code is like this:  
success = stat(FILE\_NAME, fileStatBuffer);  
Log.info (“File stat success %d”, success);  
if (success != -1)  
{  
success = (int)(fileStatBuffer-\>st\_size);  
Log.info (“File size %d”, success);  
}

Is it something obvious I’m missing?

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [October 27, 2020, 10:52pm UTC](https://community.particle.io/t/checking-file-size-returns-the-same-size/58219/2 "2020-10-27T22:52:41Z")

</div>

What is the declaration for `fileStatBuf`?

Normally you’d use it like this:

```auto
struct stat sb;
success = stat(FILE_NAME, &sb);

```

Note that the declaration of `struct stat` is not a `*`; you need to allocate the actual structure but the use `&sb` as the parameter because stat takes a pointer to the structure you allocated.

---

<div class="post-metadata">

**Author:** ![wasphax](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@wasphax](https://community.particle.io/u/wasphax)\
**Post date:** [October 28, 2020, 11:58pm UTC](https://community.particle.io/t/checking-file-size-returns-the-same-size/58219/3 "2020-10-28T23:58:11Z")

</div>

Thank you, @rickkas7  
Yeah I think I had the syntax wrong. Working now. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/2/3291e3c9351789fe8620ae5bcec8d3fec67ff221.png) [@system](https://community.particle.io/u/system)\
**Post date:** [April 29, 2021, 11:58am UTC](https://community.particle.io/t/checking-file-size-returns-the-same-size/58219/4 "2021-04-29T11:58:16Z")

</div>

Closed on April 29, 2021, 11:58am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
