Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows vs Linux file modes

On a windows machine, I am trying to get a file's mode using the os module in python, like this (short snippet):

import os
from stat import *

file_stat = os.stat(path)
mode = file_stat[ST_MODE]

An example for the mode I got for a file is 33206.

My question is, how can I convert it to the linux-file mode method? (for example, 666).

Thanks to all repliers!

Edit:

found my answer down here :) for all who want to understand this topic further:

understanding and decoding the file mode value from stat function output

like image 905
Ofer Arial Avatar asked Sep 27 '26 03:09

Ofer Arial


1 Answers

Check if this translates properly:

import os
import stat

file_stat = os.stat(path)
mode = file_stat[ST_MODE]
print oct(stat.S_IMODE(mode))

For your example:

>>>print oct(stat.S_IMODE(33206))
0666

Took it from here. Read for more explanation

like image 112
Mohammad Yusuf Avatar answered Sep 29 '26 15:09

Mohammad Yusuf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!