Why is relative path to audio file not working with subfolder?

545 views Asked by At

I'm working on a project in VSCode and my folder configuration is currently laid out as the following:

  • workspaceFolder
    • bin
    • src
    • resources
      • music

When I build the project I have it specified in the tasks.json file as below:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C++ Program",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/Fe:",
                "${workspaceFolder}\\bin\\theProgram.exe",
                "${workspaceFolder}\\src\\*.cpp"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

This builds my 2 cpp files in /src and creates an exe in the /bin folder, as expected. What isn't functioning as I'd expect is the audio. I cannot figure out why the configuration I'd want (below) doesn't work.

Within the main .cpp file (path = ${workspaceFolder}\src\main.cpp) I have the following variable that is used by the windows.h mciSendStringW function:

wstring current_song;
current_song = L"../resources/music/song.mp3";

I would expect this to work - both the SRC cpp AND the program exe are located one folder beyond the resources folder, but the relative path doesn't seem to work.

I suspected the relative path was that of the workspaceFolder, so I tested changing the path to:

current_song = L"./resources/music/song.mp3";

and the audio still did not work when running the exe from the /bin folder. When I build and move the exe from the /bin directory to the workspaceFolder, the audio plays fine.

Why isn't the ../ file path working, or is there something else at play here that I'm not understanding regarding relative file paths and CL building in VSCode?

0

There are 0 answers