Get a file size in a script


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

import os

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

But my file exists. Why does it not work ?


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).

I tried this code below :

import os
path="C:\Users\CEC3\Desktop\De côté\CAMPAGNE - Mesure température v2.xlsm"
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.

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.

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:

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