0

I created a function to read excel sheet read_Excel_file(path) that return a list contains some data from a specific Column.

and in the main code I search all the excel files (where the name start Design) and this excel file should be saved in a folder Design. If I find the excel file, I call the function read_Excel_file.

Please find below the code:

import openpyxl as opx
import os


for r, d, f in os.walk('.'):
    for file in f:
        if '.xlsx'  and 'design' in file:
            #print(r)
            if r.endswith('\Design'): 
                print(file)                     
                read_Excel_file(file)                

but I get the error :

No such file or directory

even if I am sure that I have this file in my directory

Do you think that I have path problem?

PS: I add print(file) just to check the name of the file, but when read_Excel_file(file) after that I have the error.

Can you help me please?

Merkhan
  • 15
  • 8
  • Hey @Meryem, I think you can simplify your code to a **minimal** working example. As far as I understood your problem, it's only related to finding and opening files using `os.walk(...)` and the openxlsx part is not relevant at all... – koks der drache Nov 28 '19 at 09:32
  • 1
    @ Konstantin, I import openxlsx to read some data from Excel sheet – Merkhan Nov 28 '19 at 09:48

1 Answers1

1

File is just the name of the file. You are missing the complete adress. You need to add the root part of the address.

Just do:

filepath = os.path.join(r, file)
read_Excel_file(filepath) 
Nerdrigo
  • 308
  • 1
  • 5
  • 14