"Error: File or directory does not exist" BUT they do exist as confirmed by os.listdir
<p>I am writing a program that should read in a number of csv files from a directory and do some analysis on each file. I have these functions:</p>

<pre><code># Function reads in files and saves data into 2 dimensional array
def ReadInFiles(name):
  try:
    data = []
    fname = csv.reader(open(name, 'r'))
    #print 'read in file: ' + str(fname)
    rowCount = 0
    for row in fname:
      if rowCount != 0: # skip headings
        data.append(row)
      rowCount += 1
      #print name + ' ' + str(row) + ' read in successfully \n'                
  except IOError: "Can't read files"


  return data


#Function reads in files in a folder  
def ReadDirectory (dirName):
  try:
    Data = []        
    for files in os.listdir(dirName):
      print '\n FILE: ' + files
      Data = ReadInFiles(files)
      AnalyzeData(Data, daysElapsed, columns = 4)

  except IOError:
      print 'Directory does not exist!'

  return
</code></pre>

<p>The weird thing about it is if I ignore the ReadDirectory function and use just the ReadInFile function, it works perfectly (files are read in without any issues) but once I call ReadInFunction from ReadDirectory, I get the error IOError: [Errno2] File or Directory does not exist: logfile.csv
Using os.listdir to list the files in the directory works perfectly too. </p>

<p>I have the folder containing the csv files as a sub directory in the directory that contains the source code. I noticed that if I place copies of the files in the source code directory as well, my scripts works perfectly but if I remove those copies, I start getting the error again.</p>

<p>I have searched previous posts and tried double slashes, / but nothing works. I have checked the permissions on the folder but it doesn't help either. </p>

<p>Any help will be appreciated!!</p>

<p>Thank you.</p>

<p>P.S. I am fairly new to python so please excuse my possibly bad code</p>
