# Relative Path to File with File Sink/Source

**URL:** <https://www.ruby-forum.com/t/relative-path-to-file-with-file-sink-source/234597>\
**Category:** GNU Radio\
**Created:** [March 16, 2015, 6:52pm UTC](https://www.ruby-forum.com/t/relative-path-to-file-with-file-sink-source/234597 "2015-03-16T18:52:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [March 16, 2015, 6:52pm UTC](https://www.ruby-forum.com/t/relative-path-to-file-with-file-sink-source/234597/1 "2015-03-16T18:52:59Z")

</div>

Easy question here. I’m trying to use a relative path with file  
sink/source. It errors out with “can’t open file”.

I’m assuming the path is relative to the location of the .grc file  
location.

If the location of the .grc file was: /home/user1/proj1/devel/myfile.grc  
And a data file was here: /home/user1/proj1/dat/datafile.dat  
Then the path I use in file source is: …/dat/datafile.dat

What do I need to change to make this work?

Thanks,  
Rich

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [March 16, 2015, 7:01pm UTC](https://www.ruby-forum.com/t/relative-path-to-file-with-file-sink-source/234597/2 "2015-03-16T19:01:27Z")

</div>

You’re probably not running the script from where the .py is, but from  
where GRC started. Relative paths are relative to that folder.  
That means that if you run gnuradio-companion from your home directory  
(which is probably the default when you just open it from some menu),  
then paths are relative to /home/user1.

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [March 16, 2015, 7:12pm UTC](https://www.ruby-forum.com/t/relative-path-to-file-with-file-sink-source/234597/3 "2015-03-16T19:12:24Z")

</div>

Hmmm. That means I have to specify the directory users must start grc  
from  
to keep from erroring out?

Rich

On Mon, Mar 16, 2015 at 10:59 AM, Marcus Müller  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [March 16, 2015, 7:32pm UTC](https://www.ruby-forum.com/t/relative-path-to-file-with-file-sink-source/234597/4 "2015-03-16T19:32:45Z")

</div>

On 03/16/2015 02:10 PM, Richard B. wrote:

> Hmmm. That means I have to specify the directory users must start grc  
> from to keep from erroring out?
> 
> Rich  
> This a very generic Linux thing. Nothing to do with GRC or Gnu Radio  
> specifically. When you hand the operating system a relative path, it is  
> interpreted in the context of the current directory. That is  
> uniformly true.

If that “doesn’t work for you”, you can always come up with a little  
wrapper script that places your user process in the desired directory  
before  
starting the actual thing you’re wanting to run.

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [March 16, 2015, 7:46pm UTC](https://www.ruby-forum.com/t/relative-path-to-file-with-file-sink-source/234597/5 "2015-03-16T19:46:20Z")

</div>

The problem I have with absolute paths, is that I use Git, and when I  
clone  
a repo to a new computer, with different user names and directory  
structures, all the existing absolute paths will be broken. The only  
thing  
I can ensure is the structure of the Git repo will be the same.

Thanks for clearing that up. I understand what I have to do now.

Rich

On Mon, Mar 16, 2015 at 11:42 AM, Marcus Müller  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [March 16, 2015, 7:44pm UTC](https://www.ruby-forum.com/t/relative-path-to-file-with-file-sink-source/234597/6 "2015-03-16T19:44:38Z")

</div>

Generally, you’d expect that someone with a file sink/source would  
either use absolute paths to ensure there’s no ambiguity, or would like  
to see the paths behave relative to the current working directory of the  
process, which is what I’d expect from a unix program.

However, you can add an import block; “import  
os\nos.chdir(/the/right/directory)”, but that would have exactly the  
same effect as just specifying absolute paths.

Greetings,  
Marcus
