The Python programming language is a very powerful computer language. The Python programming language has very simple skills in actual operations, today we will introduce how to use the OS in the Python programming language. path. isdir () function to determine whether the path is a directory.
Determine whether the program is a directory in the Python Programming Language
In the Python programming language, you can use the OS. path. isdir () function to determine whether a path is a directory. The function prototype is as follows.
- os.path.isdir(path)
The parameter meanings are as follows. Path. The following example checks whether E: \ book \ temp is a directory.
- >>> import os
- >>> os.path.isdir('E:\\book\\temp')
Determine whether E: \ book \ temp is a directory
- True
Table E: \ book \ temp is a directory
Determine whether the Python programming language is a file
In the Python programming language, you can use the OS. path. isfile () function to determine whether a path is a file. The function prototype is as follows.
- os.path.isfile(path)
The parameter meanings are as follows. Path: The path to be determined. The following example checks whether E: \ book \ temp is a file.
- >>> import os
- >>> os.path.isfile('E:\\book\\temp')
Determine whether it is a file
- False
E: \ book \ temp is not a file or above. It is an introduction to how to use the Python programming language to determine whether it is a directory or whether it is a directory.