-1
for folder, sub_folders, files in os.walk('D:\\excel'):
    print(f"Currently looking at {folder}")
    print('\n')
    print('The subfolder are: ')
    for sub_fold in sub_folders:
        print(f"Subfolder: {sub_fold}")
    print('\n')
    print("the files are: ")
    for f in files:
        print(f"File: {f}")

I am currently using the os.path to locate all of my files in that current directory, but I only wanted to select files that ended in "RPM_AvgCylP_PStats", I am brand new so I am not really good with the logic.

https://i.stack.imgur.com/08vwd.png

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • Please review the posting guidelines and refrain from using pictures of text in your question. – possum Feb 14 '21 at 19:07
  • [str.endswith](https://docs.python.org/3/library/stdtypes.html#str.endswith) – SuperStormer Feb 14 '21 at 19:15
  • Does this answer your question? [Get a filtered list of files in a directory](https://stackoverflow.com/questions/2225564/get-a-filtered-list-of-files-in-a-directory) – Tomerikoo Feb 14 '21 at 19:35

1 Answers1

0

if you can, try to use pathlib instead, since this is designed for dealing with tasks like this.

if can't, simply change the last for loop to:

for f in files:
    if f.replace(".txt",'').endswith( "RPM_AvgCylP_PStats"):
        print(f"File: {f}")
user3224611
  • 84
  • 1
  • 7