Reading a file using a UNC - help!

richard.kessler at matteicos.com richard.kessler at matteicos.com
Tue Sep 26 16:06:32 EDT 2006


I have the simplest need...to read a file full of file names(unc) and
then check to see if each of these files exists.  I tried with the
following program, but always get file not found, even when it is
there. If I type in the file name as a literal it works...

Little program:

#This module checks for file existence
import string
import sys

def MainProcess():

    fileList = "c:\a_list_of_filenames.txt"
    inputFiles = open(fileList,"r")

    cnt = 0
    cntNotFound = 0

    for x in inputFiles:
        cnt = cnt + 1
        try:
            x = x.replace("\\","\\\\")
            x = x.replace("\n","")
            open(x,"rb")
            #open('\\\\myserver\\myshare\\myfile.dat',"r")  #works when
hard coded like this
        except IOError, (errno, strerror):
            print "I/O error(%s): %s" % (errno, strerror)
            cntNotFound = cntNotFound + 1
            print x + " Not Found"
        except ValueError, (errno,strerror):
            print "Some other error! " + str(errno) + " " + strerror
        else:
            print "Found " + x

    print str(cnt) + " total..."
    print str(cntNotFound) + " not found..."

if __name__ == '__main__':
    MainProcess()

Many thanks to anyone in advance to can tell me what I am doing wrong!
Platform is XP with PythonWin.

Richard Kessler
richard.kessler at matteicos.com




More information about the Python-list mailing list