I'm trying to run a program in Python to run a module to process data from my smartwatch. I've had it working before but I've changed the filepath variable and now no matter what I try I can't get it to work.
I'm a mac user and when I try to run the script in terminal I get the following error:
Traceback (most recent call last):
File "Descentlog_manual.py", line 53, in <module>
fitfilelist = FitFileList(directory = '/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands')
File "Descentlog_manual.py", line 21, in __init__
for fitfilename in os.listdir(self.directory):
FileNotFoundError: [Errno 2] No such file or directory: '/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands'
(base) Edwards-MBP:FarneIslands edwibberley$ python Descentlog_manual.py
/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands
From other answers on here most people seem to solve the problem by using an absolute filepath as opposed to a relative but I can't see how this is my issue. When I pwd directory I get the filepath as included in my code so I can't see where I'm going wrong.
My code from the script is below.
import os
class FitFile:
def __init__(self,name,maxtime=2,nonumber=True,apnea=False):
self.name = name
self.maxtime = maxtime
self.nonumber = nonumber
self.apnea = apnea
class FitFileList:
def __init__(self,directory):
self.fitfilelist = []
self.directory = directory
for fitfilename in os.listdir(self.directory):
if os.path.isfile(fitfilename) == True and fitfilename.endswith('.fit'):
self.fitfilelist.append(fitfilename)
def ProcessFitFiles(fitfilelist):
for files in fitfilelist.fitfilelist:
fit_file = FitFile(name = files)
#currently setup to produce a seperate .xml file for each dive, minimum time threshold will be taken from above
from fit2subsEW_module import settings
settings.fit_files = [fit_file.name]
settings.out_subslog = fit_file.name + '.xml'
settings.min_time = fit_file.maxtime
settings.no_numbering = fit_file.nonumber
settings.apnea = fit_file.apnea
print('fit file settings', settings.fit_files)
print('fit file type',type(settings.fit_files))
settings.check_settings()
from fit2subsEW_module import start_processing
start_processing()
fitfilelist = FitFileList(directory = '/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands')
ProcessFitFiles(fitfilelist)
Any help would be greatly appreciated as I've been going round in circles on this and getting nowhere.
Edit - @Osmann Durdag
When I tried your second solution I got the following error message:
(base) Edwards-MacBook-Pro:FarneIslands edwibberley$ python Descentlog_manual.py Traceback (most recent call last): File "Descentlog_manual.py", line 54, in fitfilelist = FitFileList(directory = '/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands') File "Descentlog_manual.py", line 23, in init for fitfilename in os.listdir(self.directory): FileNotFoundError: [Errno 2] No such file or directory: '/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands' (base) Edwards-MacBook-Pro:FarneIslands edwibberley$ python Descentlog_manual.py /Users/edwibberley/Garmin_descent_FIT_process/FarneIslands Traceback (most recent call last): File "Descentlog_manual.py", line 54, in fitfilelist = FitFileList(directory = '/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands') File "Descentlog_manual.py", line 22, in init print(os.listdir(self.directory)) FileNotFoundError: [Errno 2] No such file or directory: '/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands' (base) Edwards-MacBook-Pro:FarneIslands edwibberley$