path problem when file reading Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
dsdanielko
Active Member
Posts: 33
Joined: Sat Mar 12, 2016 3:12 pm

path problem when file reading

Post by dsdanielko »

I have run into a problem with the compiled binary and directories/paths.

Although the source file is stored in the folder 'src' in the project folder, it seems any paths for file I/O in the code is done relative to the parent project folder and not 'src' folder. This leads to the undesired behavior where even the compiled binary processes any paths as being relative to the parent folder of the folder that contains the binary.

Is there a way to set the working directory to be where the binary is stored and not its parent folder?

Kind of hard to explain but if you have the binary stored like this:
Folder 1
|-Folder 2
|-|-binary.xe
|-|-file.txt
and if binary.xe has:

Code: Select all

fd = _open("file.txt", O_RDONLY, 0);
_open fails because "file.txt is in Folder 2 instead of Folder 1.
If file.txt was moved to Folder 1, the _open succeeds.

Please help.
Thanks


View Solution
dsdanielko
Active Member
Posts: 33
Joined: Sat Mar 12, 2016 3:12 pm

Post by dsdanielko »

Update: It seems I was mistaken. The paths seem to be relative to whereever you use xrun from. In my case I call xrun from a batch file in folder 1 which is why I am getting this behavior i believe.

Is there a way to change the relative path to folder 2?
Gothmag
XCore Addict
Posts: 129
Joined: Wed May 11, 2016 3:50 pm

Post by Gothmag »

You could just build the path relative to your running folder. ../ would be up one directory. If your tree is right you could just just /folder2/file.txt but you should make sure every folder name is simple as possible, I'm not sure what convention they use, it may have limited #of characters for file names and directories. Try it and if it isn't working you'll have to figure out what the names are actually seen as.
dsdanielko
Active Member
Posts: 33
Joined: Sat Mar 12, 2016 3:12 pm

Post by dsdanielko »

Sadly folder 2 is not the only folder in folder 1. Folder 1 contains Folder 2, 3, 4 and so on until 32. Furthermore, each folder contains the same binary.xe but a unique file.txt. So I cannot hardcode the path as /folder2/file.txt since every other binary.xe would then check the folder 2 file.txt
User avatar
ers35
Active Member
Posts: 62
Joined: Mon Jun 10, 2013 2:14 pm

Post by ers35 »

Change the current directory before calling xrun:

Code: Select all

REM setup environment
call "C:\Program Files (x86)\XMOS\xTIMEcomposer\Community_14.1.2\SetEnv.bat"
cd "Folder 2"
xrun binary.xe
cd ../"Folder 3"
xrun binary.xe