Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open file inside folder in current directory using fopen

Tags:

c

fopen

I want to open a file that is inside a folder in the current working directory like so:

fopen("/folder/file.txt","r");

I'm unable to do so in this way, i get a "No such file or directory" error.

How can i do this properly?

Thank you in advance for any help.

like image 306
MonkeyImpala Avatar asked Apr 10 '15 12:04

MonkeyImpala


Video Answer


1 Answers

You have to mention that is a current directory. Try this,

fopen("./folder/file.txt","r");

Or

fopen("folder/file.txt","r");

If you mentioning like this /folder/file.txt it will search the directory from the root directory. So this is the reason for getting the error.

like image 59
Karthikeyan.R.S Avatar answered Sep 20 '22 16:09

Karthikeyan.R.S