0

There are a lot of subdirectories in a directory. Every Subdirectory name ends with a date. I want to to open a subdirectory that ends with today's Date.

Here is my code so far. But it is not Working.

import datetime
now = datetime.datetime.now()
currentdate = now.strftime("%d")
currentmonth = now.strftime("%B")
print(currentdate)
print(currentmonth)


path = 'C:\\Users\\Mondoc\\Desktop\\SweetMemories'

for folder in path:
    if folder.endswith(currentdate):
        pathtofolder = folder
import subprocess
subprocess.Popen('C:\\Users\\Mondoc\\Desktop\\SweetMemories'+pathtofolder)

My code is not working

  • Hint: [pathlib](https://docs.python.org/3/library/pathlib.html) is a great tool when dealing with paths and filenames in Python. – FObersteiner Jun 05 '22 at 07:59

1 Answers1

0

You are iterating a string actually. Is this what you want?

import os

# for folder in path:
#    if folder.endswith(currentdate):
for name in os.listdir(path):
    if os.path.isdir(name) and name.endswith(...):
        ...
yhgu2000
  • 193
  • 6