I am trying to develop a Python program that will process files ending in ” 2″. As a start I have obtained a program from Gemini that will simply print files ending in ” 2″ but it does not work and I cannot figure out why. One version of Python code that does not work is:
if __name__ == "__main__":
files = find_files_ending_with 2()
if files:
print("Files ending with ' 2':")
for file in files:
print(file)
else:
print("No files found ending with ' 2'.")
The Gemini code cannot find and print the files ending in ” 2″.
It cannot find file ending in just 2.
I checked and the file names do not contain ay special characters that python should have problems processing.
I have gotten other code from Gemini that will find files containing a certain word and they work fine.
The problem seems to be having python find file names ending in something as opposed to file names containing something.
Mike Anona is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1