I am trying to write a program in python that will take a windows file path (uses backslashes not forward slashes) and converts the file to another file type. I think some combination of input()
and windows using backslashes is what is causing errors.
For example, the user would input something like
C:\Users\user\Downloads\file.tdms
I want to tell the user to copy the file path from their file explorer and paste it into the program. I cannot alter what the user inputs, it has to be in the above form.
Here is my code thus far:
from nptdms import TdmsFile
from pathlib import Path, PurePosixPath
path = Path(input('enter file path: '))
path1 = PurePosixPath(path)
print(path1)
with open(path1, mode='r') as f:
tdms_file = TdmsFile.read(f)
tdms_file.to_csv(path + '.csv')
Here is the error I get:
(base) H:\Private\ahirani\python TDMS to CSV>testing.py
enter file path: "C:/Users/user/Downloads/file.tdms"
"C:/Users/user/Downloads/file.tdms"
Traceback (most recent call last):
File "H:\Private\ahirani\python TDMS to CSV\testing.py", line 11, in <module>
with open(path, mode='r') as f:
OSError: [Errno 22] Invalid argument: '"C:/Users/user/Downloads/file.tdms"'