About 50 results
Open links in new tab
  1. Extract file name from path, no matter what the os/path format

    Dec 5, 2011 · Which Python library can I use to extract filenames from paths, no matter what the operating system or path format could be? For example, I'd like all of these paths to return me c: …

  2. python - How do I correctly use the os.path to locate a file stored in ...

    May 23, 2022 · 0 I'm new to python and I've not used os.path that often, but as my projects grew and I started trying to integrate multiple folders together, I realized that it is probably best that I start using …

  3. python - Find the current directory and file's directory - Stack Overflow

    How do I determine: the current directory (where I was in the shell when I ran the Python script), and where the Python file I am executing is?

  4. python - How do I get the full path of the current file's directory ...

    2812 The special variable __file__ contains the path to the current file. From that we can get the directory using either pathlib or the os.path module. Python 3 For the directory of the script being run:

  5. python - Should I use `import os.path` or `import os`? - Stack Overflow

    According to the official documentation, os.path is a module. Thus, what is the preferred way of importing it? Should I always import it explicitly? import os.path Or is importing os enough? impor...

  6. pathlib.Path vs. os.path.join in Python - Stack Overflow

    Apr 15, 2021 · When I need to define a file system path in my script, I use os.path.join to guarantee that the path will be consistent on different file systems: from os import path path_1 = …

  7. python - How to switch from Path to os.path and vice versa? - Stack ...

    Dec 15, 2020 · The phrase some libraries still expect me to use os.path seem to confuse you. os.path is a module that simply treats paths as strings - as opposed to pathlib which treats them as specialized …

  8. Python os.path.join on Windows - Stack Overflow

    I am trying to learn python and am making a program that will output a script. I want to use os.path.join, but am pretty confused. According to the docs if I say: os.path.join('c:', 'sourcedir')...

  9. python - pros and cons between os.path.exists vs os.path.isdir - Stack ...

    Feb 25, 2013 · 146 os.path.exists will also return True if there's a regular file with that name. os.path.isdir will only return True if that path exists and is a directory, or a symbolic link to a directory.

  10. How to get an absolute file path in Python - Stack Overflow

    Sep 9, 2008 · 41 import os os.path.abspath(os.path.expanduser(os.path.expandvars(PathNameString))) Note that expanduser is necessary (on Unix) in case the given expression for the file (or directory) …