How to create a filesystem node using Python?

PythonServer Side ProgrammingProgramming

os.mknod(path, mode=0o600, device=0, *, dir_fd=None) creates a filesystem node (file, device special file or named pipe) named path. The mode specifies both the permissions to use and the type of node to be created, being combined (bitwise OR) with one of stat.S_IFREG, stat.S_IFCHR, stat.S_IFBLK, and stat.S_IFIFO (those constants are available in stat). This function can also support paths relative to directory descriptors. It is only available on Unix. It can be used as follows:

import os
import stat
filename = '/tmp/tmpfile'
mode = 0600|stat.S_IRUSR
# filesystem node specified with different modes
os.mknod(filename, mode)

Runnig the above code will create a file in /tmp directory with a name tmpfile.

raja
Published on 26-Dec-2017 14:45:16
Advertisements