API · Python
Python os.path.normcase() Method
The os.path.normcase() is an in-built Python function used to normalize the case of any given pathname.
On this page
Python’s os.path.normcase() method is the most efficient way of normalizing the case of a specified path. On Windows OS, path normalization includes converting all characters to the lowercase and any forward slash (/) into a backslash (\).
Syntax of Python os.path.normcase() Method
os.path.normcase(path address)
Parameters
path address |
This is the address object of a file system path or a symlink. This object can either be an str or bytes. |
Return
This method returns a string value, which is a path string containing the normalized case of a file.
Example Codes: Use the os.path.normcase() Method on Windows OS
import os
path = "/home///user/Documents"
normalize = os.path.normcase(path)
print(normalize)
path = "/home/./Documents"
normalize = os.path.normcase(path)
print(normalize)
path = "/home/user/temp/../Documents"
normalize = os.path.normcase(path)
print(normalize)
Output:
\home\\\user\documents
\home\.\documents
\home\user\temp\..\documents
Note that on Windows OS, theos.path.normcase() method converts /A/BB/C to \a\bb\c.
Example Codes: Use the os.path.normcase() Method on OS Other Than the Windows OS
import os
path = "/home///user/Documents"
normalize = os.path.normcase(path)
print(normalize)
path = "/home/./Documents"
normalize = os.path.normcase(path)
print(normalize)
path = "/home/user/temp/../Documents"
normalize = os.path.normcase(path)
print(normalize)
Output:
/home///user/Documents
/home/./Documents
/home/user/temp/../Documents
This method returns an unchanged path address on another operating system, excluding the Windows OS.