Reputation: 63
I'm having a problem with running files in command prompt, keeps saying "no such file or directory"
I copy n pasted a pathway for an existing file and just swapped the file with the one that im being told does not exist. Tried various small changes in syntax as well.
in text editor:
from sys import argv
script, filename = argv
txt = open(filename)
print(f"heres the file you wanted:{filename}:")
print(txt.read())
print("type the filename again:")
file_again=input("> ")
txt_again=open(file_again)
print(txt_again.read())
in BASH:
python3.7 /users/philipedwards/Documents/ex15.py test.txt
Upvotes: 2
Views: 20536
Reputation: 1
For futur persons facing this problem. It's maybe because of the binary wich is 32Bits or any incompatible architercture. Here is an excellent thread referencing the same problem: No such file or directory? But the file exists!
Upvotes: 0
Reputation: 4537
I'm assuming test.txt
is in the Documents
folder. But, based on this command:
python3.7 /users/philipedwards/Documents/ex15.py test.txt
your current location might not be the Documents
directory. By specifying text.txt
you're trying to open text.txt
from the current directory, not /users/philipedwards/Documents/test.txt
.
So, either run the script from the Documents
directory:
cd /users/philipedwards/Documents
python3.7 ex15.py test.txt
Or if you don't want to change the active directory, specify the full path of the text file:
python3.7 /users/philipedwards/Documents/ex15.py /users/philipedwards/Documents/test.txt
Upvotes: 3