To get names of the file from text.txt file, we can use the open
function to open the file in read mode, read the contents of the file using readlines()
method and then use string manipulation techniques to extract the file names.
Assuming the text.txt file contains the file names separated by a new line character, the following code can be used to read the file names one by one:
main.py482 chars19 lines
The os.path.isfile()
function is used to check if a file exists at the specified path.
Note: The strip()
function is used to remove any leading or trailing white spaces or new line characters from the file name.
gistlibby LogSnag