# Get a file size in a script

**URL:** <https://forum.inductiveautomation.com/t/get-a-file-size-in-a-script/11262>\
**Category:** General Discussion\
**Created:** [February 24, 2016, 8:16am UTC](https://forum.inductiveautomation.com/t/get-a-file-size-in-a-script/11262 "2016-02-24T08:16:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [February 24, 2016, 8:16am UTC](https://forum.inductiveautomation.com/t/get-a-file-size-in-a-script/11262/1 "2016-02-24T08:16:18Z")

</div>

Hi,

I tried to know the size of a file on my computer with a python script. I wrote this code :

```auto
import os
os.stat(filename).st_size
```

But it doesn't work.  
I have this error message :

> [@](#):
>
> Traceback (most recent call last):
> 
> File "", line 1, in
> 
> OSError: (2, 'No such file or directory', 'C:\Users\CEC3\Documents\SP203\_R\xc3\xa9partitions\_Consosjour\_TURPE4.xls')

But my file exists. Why does it not work ?

Thanks,

---

<div class="post-metadata">

**Author:** ![ssmith](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@ssmith](https://forum.inductiveautomation.com/u/ssmith)\
**Post date:** [February 24, 2016, 2:08pm UTC](https://forum.inductiveautomation.com/t/get-a-file-size-in-a-script/11262/2 "2016-02-24T14:08:42Z")

</div>

It looks like your path is probably wrong (only some of your backslashes are escaped). Don’t use escaped backslashes. If you just type forward slashes in the path, it will get converted automatically to windows path format. You can also explicitly do this with the function os.path.normpath(path).

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [February 26, 2016, 11:56am UTC](https://forum.inductiveautomation.com/t/get-a-file-size-in-a-script/11262/3 "2016-02-26T11:56:15Z")

</div>

I tried this code below :

```auto
import os
path="C:\Users\CEC3\Desktop\De côté\CAMPAGNE - Mesure température v2.xlsm"
newpath=os.path.normpath(path)
filesize=os.stat(newpath).st_size
print filesize
```

“newpath” is equal to :  
C:\Users\CEC3\Desktop\De côté\CAMPAGNE - Mesure température v2.xlsm

But it shows me the same error message.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 26, 2016, 1:22pm UTC](https://forum.inductiveautomation.com/t/get-a-file-size-in-a-script/11262/4 "2016-02-26T13:22:39Z")

</div>

If the script is running in gateway context, it probably doesn’t have access to that folder structure. Try putting the file in a folder owned by the Ignition service.

---

<div class="post-metadata">

**Author:** ![ssmith](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@ssmith](https://forum.inductiveautomation.com/u/ssmith)\
**Post date:** [February 26, 2016, 5:07pm UTC](https://forum.inductiveautomation.com/t/get-a-file-size-in-a-script/11262/5 "2016-02-26T17:07:28Z")

</div>

In addition to the above…

Make your path with forward slashes otherwise if you happen to have a path that contains things like \n or \t, then it’s going to be all messed up.  
Make your path like this:

```auto
path="C:/Users/CEC3/Desktop/De côté/CAMPAGNE - Mesure température v2.xlsm"
```
