About 860,000 results
Open links in new tab
  1. python - How to read file attributes in a directory ... - Stack Overflow

    When looking for file attributes for all files in a directory, and you are using Python 3.5 or newer, use the os.scandir() function to get a directory listing with file attributes combined. This can potentially be more efficient than using os.listdir() and then retrieve the file attributes separately:

  2. Get file attributes (hidden, readonly, system, archive) in Python

    Nov 29, 2014 · Since Python 3.5, os.stat(), os.fstat() and os.lstat() returns a class os.stat_result that, on Windows systems, includes st_file_attributes. You can use the FILE_ATTRIBUTE_* constants in the stat module to check the file attributes.

  3. Use Python to List File Attributes | by Patric Raphael - Medium

    Mar 29, 2024 · I have been tasked with building a script that extracts file attributes including the name, path, and size of the file. I will use a python script to collect information about the files in...

  4. How to Retrieve and Set File Metadata and Attributes in Python

    File attributes control how files behave and how they can be accessed. Python allows you to retrieve and set attributes such as read-only and hidden status using the os and stat modules. Retrieving File Attributes. To retrieve file attributes, use the os.stat() function and constants from the stat module. The example code below checks the read ...

  5. python - List attributes of an object - Stack Overflow

    Is there a way to grab a list of attributes that exist on instances of a class? def __init__(self, number): self.multi = int(number) * 2. self.str = str(number) The desired result is that "multi, str" will be output. I want this to see the current attributes from various parts of a script.

  6. Using Python to gather files and file data within a directory…

    Aug 7, 2023 · Os.stat () = Contains all the file’s statistics or attributes that you normally see in a place like File Explorer in windows (i.e., filename, type, size, date-modified, etc.). Os.listdir () =...

  7. Working With Files in Python

    Oct 4, 2018 · Python makes retrieving file attributes such as file size and modified times easy. This is done through os.stat() , os.scandir() , or pathlib.Path() . os.scandir() and pathlib.Path() retrieve a directory listing with file attributes combined.

  8. Printing a List of Files in Directory and Subdirectories in Python

    3 days ago · import os def list_files(startpath): for root, dirs, files in os.walk(startpath): for file in files: print(os.path.join(root, file)) list_files("newdir") # Output: newdir/filename.txt. This approach is old-school, and I cannot recommend it for production due …

  9. Python List Files in a Directory - PYnative

    Feb 24, 2024 · os.walk('dir_path'): Recursively get the list of all files in a directory and subdirectories. os.scandir('path'): Returns directory entries along with file attribute information. glob.glob('pattern'): glob module to list files and folders whose names follow a specific pattern.

  10. File and Directory Access — Python 3.13.3 documentation

    2 days ago · File and Directory Access¶ The modules described in this chapter deal with disk files and directories. For example, there are modules for reading the properties of files, manipulating paths in a portable way, and creating temporary files.

  11. Some results have been removed
Refresh