Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
testing an open file
#2
you can get the mode (and much more) by using stats

for example (run from script path -- modify path as required --, probably better to use pathlib):
modified from example here: https://docs.python.org/3/library/os.html#os.scandir
import os

path = os.getcwd()
with os.scandir(path) as it:
    for entry in it:
        if not entry.name.startswith('.') and entry.is_file():
            stats = os.stat(path, follow_symlinks=False)
            print(stats)
see https://docs.python.org/3/library/stat.html on how to interpret the stat results.
Reply


Messages In This Thread
testing an open file - by Skaperen - Dec-17-2022, 02:06 AM
RE: testing an open file - by Larz60+ - Dec-17-2022, 03:26 AM
RE: testing an open file - by Gribouillis - Dec-17-2022, 07:02 AM
RE: testing an open file - by Skaperen - Dec-17-2022, 06:47 PM
RE: testing an open file - by Gribouillis - Dec-17-2022, 09:00 PM
RE: testing an open file - by Skaperen - Dec-19-2022, 03:17 AM
RE: testing an open file - by Gribouillis - Dec-19-2022, 07:37 AM
RE: testing an open file - by Skaperen - Dec-20-2022, 02:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Open/save file on Android frohr 0 386 Jan-24-2024, 06:28 PM
Last Post: frohr
  file open "file not found error" shanoger 8 1,327 Dec-14-2023, 08:03 AM
Last Post: shanoger
  How can i combine these two functions so i only open the file once? cubangt 4 942 Aug-14-2023, 05:04 PM
Last Post: snippsat
  I cannot able open a file in python ? ted 5 3,646 Feb-11-2023, 02:38 AM
Last Post: ted
  I get an FileNotFouerror while try to open(file,"rt"). My goal is to replace str decoded 1 1,453 May-06-2022, 01:44 PM
Last Post: Larz60+
  Dynamic File Name to a shared folder with open command in python sjcsvatt 9 6,264 Jan-07-2022, 04:55 PM
Last Post: bowlofred
  Open an excel file Newbie1114 1 2,374 Jun-16-2021, 09:11 PM
Last Post: Gribouillis
  How to open MIDI-file and get events in a list? philipbergwerf 7 5,146 May-29-2021, 08:24 AM
Last Post: j.crater
  Error on open of file created with tempfile.TemporaryDirectory() Brian177 4 6,465 Apr-05-2021, 07:12 PM
Last Post: Brian177
  I can't open a python file :( Oshadha 2 3,052 Mar-28-2021, 11:00 PM
Last Post: pythonprogrammer1101935

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020