Search code examples
pythonpathglob

Getting empty list when using glob.glob in python to return paths from pc


I use jupyter notebook anaconda, I need to read paths of specific files from folder

paths = glob.glob('E:\master\neural network\mit-bih-arrhythmia-database-1.0.0/*.atr', recursive=True)
paths = glob.glob('E:\master\neural network\mit-bih-arrhythmia-database-1.0.0/*.atr')
**paths = glob.glob('E:\master\neural network\mit-bih-arrhythmia-database-1.0.0\*.atr')**

I try these lines but paths returns empty


Solution

  • You need double backslashes because they're special characters:

    paths = glob.glob('E:\\master\\neural network\\mit-bih-arrhythmia-database-1.0.0\\*.atr', recursive=True)
    

    You can also use an r string instead, so that all the characters will be interpreted as normal:

    paths = glob.glob(r'E:\master\neural network\mit-bih-arrhythmia-database-1.0.0\*.atr', recursive=True)