1

I am trying to cycle through files in a folder to get information, however the path gives me a "\" and I think that may be causing issues. As an example, if I run the full code (snippet shown below), I get the path /FAU/PythonCode/Urban-Sound-Classification-master/data/train/Train\\0.wav.

How to get the correct path to show up?

Here is some minimal code:

import glob
import os

def input_to_target(base_data_path='/FAU/PythonCode/Urban-Sound-Classification-master/data/'):
    train_path = os.path.join(base_data_path + "train/Train/*.wav")
    train_files = glob.glob(train_path)
    print(train_files)
martineau
  • 119,623
  • 25
  • 170
  • 301
Joe
  • 357
  • 2
  • 10
  • 32
  • 3
    https://stackoverflow.com/questions/16333569/mixed-slashes-with-os-path-join-on-windows Basically: os.path.join() intelligently works out which slashes you need for your OS. Currently, you are providing most of them yourself and os.path.join() then fills in the two backslashes. Best to either provide all of them yourself, or let os.path.join() choose all of them. You could also replace the '//' manually, albeit a workaround: ` os.path.join().replace('\\','/')` – Steven Aug 24 '20 at 22:34
  • 1
    @Steven, thanks for your quick response. How to go about doing the first two ideas you presented? Thanks! – Joe Aug 24 '20 at 22:40
  • 2
    Well, just remove the os.path.join() and let train_path be `train_path = base_data_path + 'train/Train/*.wav'`. Glob will work out which files they are. This is assuming that this is the correct path for your OS. – Steven Aug 24 '20 at 22:41
  • Not sure why the path is now: ` /FAU/PythonCode/Urban-Sound-Classification-master/data/train/Train\0.wav` – Joe Aug 24 '20 at 22:49
  • Are you on Windows? Does this path allow you to open the file? – Steven Aug 24 '20 at 22:54
  • I am on windows 10. I am not able to open up the file as I get an empty set. – Joe Aug 24 '20 at 22:55
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220381/discussion-between-joe-and-steven). – Joe Aug 24 '20 at 22:56

0 Answers0