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 7417829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:46:22+00:00 2026-05-29T07:46:22+00:00

I am writing a program that should read in a number of csv files

  • 0

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:

# 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

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.

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.

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.

Any help will be appreciated!!

Thank you.

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

  • 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-05-29T07:46:23+00:00Added an answer on May 29, 2026 at 7:46 am

    os.listdir() returns bare file names that do not include the name of the directory the files are in.

    You probably meant:

     Data = ReadInFiles(os.path.join(dirName, files))
    

    P.S. Why is files plural when it refers to a single file name?

    P.P.S. The following except block doesn’t do anything useful and quietly ignores all errors:

    except IOError: "Can't read files"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing a program that should read input via stdin, so I have the
I have to write a program that read from a file that contains the
I'm currently writing a program that needs to compare each file in an ArrayList
I'm writing a program to read data from a file, which may be in
I am writing a program that takes in an input file from the user.
I am writing a program in MIPS that will read in signed integers from
hi I have a program that log some data in text file in specific
I am writing a C program that will read and write from/to a serial
I'm writing a C program under Windows that should send an ENTER key to
If you are writing a program that is executable from the command line, you

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.