0
for i in os.listdir(path_1):
    for j in os.listdir(path_2):
        file_name = (j.split('.')[0])
        if i.__contains__(file_name) and i.endswith('txt'):
            txt_tym = os.path.getctime(path_1 + '/' + i)
            log_tym = os.path.getctime(path_2 + '/' + j)
            if txt_tym >= log_tym:
                print('Issues found in: '+i)
            else:
                print('No issues found')

I'm using this program to compare timestamp between two files in two different directory, it has same names but different extension,
I need to show the result in a text document.If there is an issue it will print Isues found in: filename.
I need to print No issues found only if there is no single files with the issue,
Im using else inside the loop and it prints multiple times.
Please give some suggestions to this

2
  • 2
    ... create a list, add all issue-file-names to the list, print the list outside the loop - if list empty print your No issue message Commented May 17, 2020 at 17:40
  • @PatrickArtner I will try this thank you!! Commented May 17, 2020 at 17:42

1 Answer 1

1

Something like this should work:

issues_found = false
for i in os.listdir(path_1):
    for j in os.listdir(path_2):
        file_name = (j.split('.')[0])
        if i.__contains__(file_name) and i.endswith('txt'):
            txt_tym = os.path.getctime(path_1 + '/' + i)
            log_tym = os.path.getctime(path_2 + '/' + j)
            if txt_tym >= log_tym:
                print('Issues found in: '+i)
                issues_found = true

if not issues_found:
    print('No issues found')
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much!!
You're welcome. Please accept the answer if it helped you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.