About 271 results
Open links in new tab
  1. Find a file in python - Stack Overflow

    Nov 12, 2009 · import os def find(name, path): for root, dirs, files in os.walk(path): if name in files: return os.path.join(root, name) And this will find all matches: def find_all(name, path): result = …

  2. Python Program to Get the File Name From the File Path

    Aug 21, 2024 · you can use the built-in Python function split() to split the file path into a list of individual components, and then use the rsplit() method to split the last component (which …

  3. Python Get Filename From Path

    Apr 8, 2024 · There are four Python methods for getting the file name from the path: the ‘os’ module, the ‘pathlib’ module, split() and rsplit(), and regular expressions. Let’s start. Python …

  4. Get the filename, directory, extension from a path string in Python

    May 8, 2023 · In Python, you can get the filename (basename), directory (folder) name, and extension from a path string or join the strings to generate the path string with the os.path …

  5. Python: Get Filename From Path (Windows, Mac & Linux)

    Oct 8, 2021 · Learn how to use Python to get the filename from a path, with or without the file's extension, using the os and pathlib libraries.

  6. How to Find Files Using Python - Delft Stack

    Feb 2, 2024 · The sample code below shows us how to find a file in Python with the os.walk() function. import os def findfile (name, path): for dirpath, dirname, filename in os . walk(path): if …

  7. Python Program to Get the File Name From the File Path

    import os # file name with extension file_name = os.path.basename('/root/file.ext') # file name without extension print(os.path.splitext(file_name)[0]) Output. file. basename() gives the name …

  8. Extract File Name from Path for Any OS/Path Format

    Apr 22, 2023 · In Python, you can extract the file name from a file path using different methods, such as the rsplit() method, the basename() function from the OS module, and the Path …

  9. python - How to get the name of an open file? - Stack Overflow

    Nov 23, 2016 · Use this code snippet to get the filename you are currently running (i.e .py file): target_file = inspect.currentframe().f_code.co_filename

  10. 03 Methods to Get Filename from Path in Python (with code)

    Dec 16, 2022 · But how do I read a filename from the path in Python? There are three methods that we can use to get the filename from a given path in python. Some of these methods use …

Refresh