While traversing from my current path , and searching for a file , I'm having problems locating the file .
I suspect the that the path
is the blame for that due to chdir
, in the next code :
The associated folders are :
- 12,13,14 , 12 is father directory
- 13 inside 12 , 14 inside 13
- david1.txt inside 14
- get_current_dir_name() is a Linux function , not mine
I run the executable file from Desktop
, like this (here are printf-s
for trying to locating the problem) :
// doesn't work
a@ubuntu:~/Desktop$ ./exer4 12 david1.txt
Current path is :12
Current path is :/home/a/Desktop/12/13
Current path is :/home/a/Desktop/12/13/14
//////////////////////////////////////////////////
// doesn't work
a@ubuntu:~/Desktop$ ./exer4 12/13 david1.txt
Current path is :12/13
Current path is :/home/a/Desktop/12/13/14
////////////////////////////////////////////////
// doesn't work
a@ubuntu:~/Desktop$ ./exer4 12/13/14 david1.txt
Current path is :12/13/14
If I remove these lines :
chdir(path); // the problem is probably here
strcpy(path, get_current_dir_name()); // and here
Then every query that involves only a single library name - works , for example :
// works :
a@ubuntu:~/Desktop$ ./exer4 12 david1.txt
Current path is :12
Current path is :12/13
File found!
12/13/14/david1.txt-rw-rw-r-- 1 1000 1000 0 2012-06-17 08:10
Current path is :12/13/14
////////////////////////////////////////////////////////////
// works
a@ubuntu:~/Desktop$ ./exer4 12/13 david1.txt
Current path is :12/13
File found!
12/13/14/david1.txt-rw-rw-r-- 1 1000 1000 0 2012-06-17 08:10
Current path is :12/13/14
////////////////////////////////////////////////////////////
// Doesn't work
a@ubuntu:~/Desktop$ ./exer4 12/13/14 david1.txt
Current path is :12/13/14
Any idea what I'm doing wrong here ? I've tried to change countless times but nothing fixed it . Thanks