Here's one way to approach the problem in Python:
open()
function:with open("downloaded_files.txt", "r") as f:
downloaded_files = f.read().splitlines()
This will create a list called downloaded_files
containing all the filenames listed in the .txt file.
os
library to check if each file exists in the current directory:import os
for file in downloaded_files:
if os.path.exists(file):
print(f"{file} exists")
else:
print(f"{file} does not exist")
This code will loop through each filename in downloaded_files
and use os.path.exists()
to check if the file exists in the current directory. If the file exists, it will print a message saying so. If it doesn't exist, it will print a message saying so.
Note: This assumes that the .txt file lists filenames without any directory paths. If the filenames include directories, you'll need to modify the os.path.exists()
check accordingly.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-06-07 11:00:00 +0000
Seen: 7 times
Last updated: Jun 23 '21
How can I set up Gunicorn with a Django Project?
Looking for a Python Module that finds Tags for a Text describing its Content
Need a Function in Python to remove entries less than 2 digits from an Array
How can I convert a Document in Python?
How can I program a Loop in Python?
How can I enable Python Code Highlighting in Askbot?