'I am trying to open a full path file from glob but the i get [Errno 2]

8.11 So basically i am using glob.glob to search a directory and subdirectories for specific .txt files containing a specific end in the filename like so:

import glob
import pandas as pd
import os

cwd = os.getcwd()

files = []
files = glob.glob(cwd + '/**/*_chr.txt', recursive=True)


test1 = pd.read_csv(files[0], sep='\t')

Output for files[0] seems fine

print(files[0])
C:\Users\ggAas\hobO\tt & rr - dds\ee - asasr\bb ppD\30 DD ffs\MM EE\666-881\2022-01-14 68466-801 BB can\66-881_M_S_MTS_PMIN\666_PPP_TT_666-801_MCV10_SN5_MTS2013771108_PMIN_10_chr.txt

I know the path contains alot of spaces and other not so nice stuff. But when i copy/paste in windows stifinder the files opens without and problem

The error i get

FileNotFoundError: [Errno 2] No such file or directory:

I've tried to "reshape" the path without any luck and i've copying the path directly into pd.read csv but the error persits. I think the path just isnt accepted due to the bad things in it. Is there anything i can do for python(spyder) to accept the path?



Solution 1:[1]

I am an idiot :D the filepath exceeded 260 char

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mechanico