About 186,000 results
Open links in new tab
  1. How to split a dos path into its components in Python

    import os path = os.path.normpath(path) path.split(os.sep) First normalize the path string into a proper string for the OS. Then os.sep must be safe to use as a delimiter in string function split.

  2. Extract a part of the filepath (a directory) in Python

    Mar 20, 2021 · I need to extract the name of the parent directory of a certain path. This is what it looks like: C:\\stuff\\directory_i_need\\subdir\\file.jpg I would like to extract directory_i_need.

  3. 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: …

  4. python - Extracting extension from filename - Stack Overflow

    Nov 23, 2019 · Unlike most manual string-splitting attempts, os.path.splitext will correctly treat /a/b.c/d as having no extension instead of having extension .c/d, and it will treat .bashrc as having no …

  5. How to use "/" (directory separator) in both Linux and Windows in …

    Apr 15, 2013 · In this case the relevant one is os.path. Especially join which creates a new pathname from a directory and a file name or directory and split that gets the filename from a full path.

  6. cross-platform splitting of path in python - Stack Overflow

    Jan 3, 2011 · except in python 2.7 you have os.path.normpath(), so normalize the path, then split it using os.sep. The objective should be behavorial identity, not literal identity.

  7. Separating file extensions using python os.path module

    Jun 25, 2013 · I'm working in python with os.path.splitext() and curious if it is possible to separate filenames from extensions with multiple "."? e.g. "foobar.aux.xml" using splitext.

  8. python - How to split path with slashes? - Stack Overflow

    Apr 2, 2014 · I have a requirement for adding and splitting path in my app.I want to work with this app on windows and linux.Here is my code to add paths path = os.path.join(dir0,dir1,dir2,fn) But when i am

  9. file - Split filenames with python - Stack Overflow

    Mar 28, 2017 · 3 To deal with path and file names, it is best to use the built-in module os.path in Python. Please look at function dirname, basename and split in that module.

  10. python - Benefits of os.path.splitext over regular .split ... - Stack ...

    In this other question, the votes clearly show that the os.path.splitext function is preferred over the simple .split('.')[-1] string manipulation. Does anyone have a moment to explain exactly why ...