In pset8 import file on running the command ./import /pset8/US.txt the file is not opening.I have tried many methods but the interpreter says the file does not exists, although I can clearly see it (with ls). Here is my code:


// check if file exists
    // open the file
    $handle = fopen("{$argv[1]}", "r");

    // parse the file and insert into table 'places'
    while (($location = fgetcsv($handle, 0, "\t")) !== FALSE)
        CS50::query("INSERT INTO places (country_code, postal_code,place_name,admin_name1,admin_name2,admin_name3,admin_code3,latitude,longitude,accuracy) VALUES(?,?,?,?,?,?,?,?,?,?)", $location[0],$location[1],$location[2],$location[3],$location[4],$location[5],$location[6],$location[7],$location[8],$location[9]);

    // close the file

else exit("file doesn't exist");

but it's prompting again and again "file doesn't exist". I have already changed the permissions of US.txt, still its undiscoverable. What can be the reason for such strange behaviour.


1 Answer 1


Your second argument to the command is saying "get the the file US.txt, located inside the folder pset8, which is in the root (/) directory".

But pset8 probably isn't inside /. It's most likely inside ~/workspace (which is a shorthand for /home/ubuntu/workspace).

So assuming your file is inside your pset8 directory and import is elsewhere, this should work:

./import ~/workspace/pset8/US.txt

Another way would be to put both import and US.txt inside the same folder. If you do that, you can simply:

./import US.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .