Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8502615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:32:06+00:00 2026-06-11T01:32:06+00:00

I am trying to build this script to check if a file on a

  • 0

I am trying to build this script to check if a file on a remote server contains a set suffix, IE .ok, .err, .log. I can’t figure out why I am getting the return that I am
"('\\\\THPNWSS5\\d$\\DA$Utils\\log\\networker', [], ['P3EWS.err']) nothing is equal“
I know there is something wrong with my try statement but I can’t see it.

    chkbkpstats = csv.reader(file('c://temp//networkerservers1.csv'))

    srvrs = []
    for row in chkbkpstats:
        srvrs.append({'Name' : row[0], 'Instance' : row[1]})

    for srvr in srvrs:
        srvrName = (srvr['Name'])
        srvrInst = (srvr['Instance'])
        w2k3chk = r'\\%s\d$\DA$Utils\log\networker' % srvrName
        w2k8chk = r'\\%s\c$\ProgramData\folder\DA$Utils\log\networker' % srvrName

        try:
            c = wmi.WMI(srvr['Name'])
        except:
            print 'Error connecting to %s to check OS version' % srvrName

        else:
            osVer = c.Win32_OperatingSystem()[0].Caption
            if '2003' in osVer:
                for file in os.walk(w2k3chk):
                    print file
                    try:
                        if srvrInst == srvrInst + ".log":
                            print 'The Backup for %s on %s still running' % (srvrInst, srvrName)
                        if srvrInst == (srvrInst + ".ok"):
                            print 'Completed Successfully'
                        if srvrInst == (srvrInst + ".err"):
                            print 'Backup failed'
                    except:
                        print 'nothing is equal'
                #print '%s is w2k3' % srvr['Name']
            elif '2008' in osVer:
                print '%s is w2k8' % srvr['Name']
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:32:07+00:00Added an answer on June 11, 2026 at 1:32 am

    While @लंड has pointed out the most pressing error in your current code, his suggested fix, file == (srcInst + ".log") won’t work either. That’s because the os.walk function doesn’t just return filenames. It returns a generator of three-tuples, each consisting of a directory, a list of subdirectories (which will also be walked) and a list of files. You need an extra loop to go over the individual files.

    Something like this should work:

    found = False
    for folder, subfolders, files in os.walk(w2k3chk):
        for file in files:
            if file == srvrInst + ".log":
                found = True
                print 'The Backup for %s on %s still running' % (srvrInst, srvrName)
            elif file == (srvrInst + ".ok"):
                found = True
                print 'Completed Successfully'
            elif file == (srvrInst + ".err"):
                found = True
                print 'Backup failed'
    if not found:
        print 'No file found'
    

    If you’re sure there should only ever be a single file in the folder you’re searching, you can simplify that a bit:

    try:
        folder, subfolders, files = next(os.walk(w2k3chk)):
        file = files[0]
        if file == srvrInst + ".log":
            print 'The Backup for %s on %s still running' % (srvrInst, srvrName)
        elif file == (srvrInst + ".ok"):
            print 'Completed Successfully'
        elif file == (srvrInst + ".err"):
            print 'Backup failed'
        else:
            print 'Unknown file found: %s' % (file)
    except (StopIteration, IndexError): # exceptions if folder or file doesn't exist
        print 'No file found'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to check the ant build script's argument is set or not.
I'm trying to build a Synergy AutoStart script as per this article , the
I'm trying to build a screen like this: How can I split my cell
I'm trying to build a screen like this: How can I put my span
I am trying to set up Jenkins to continually check out and build code
Im trying to make this batch script check on resumption that it has not
I'm trying to build an authentication script and i'm trying to get this one
I'm trying to run this script: import re, os def build_pool(cwd): global xtn_pool, file_pool
I'm trying to build this layout: I have this at this time: http://jsfiddle.net/Gh6mB/12/ The
Trying to build openssl-fips-2.0 with NDK, before I was lucky found this link and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.