I am currently working on a server. I’ve created my own directory but need access to files located in a different directory on the server. Basically, I have code that needs access to the files located in another directory on the server but I do not know how to go about doing this. Is there a command in my code that I can add or is there something on the command line i can type? The error I get in my code looks like this:
[aburac1][mcbbigram][/ruths/data/aburac1] python get-contribs.py
Traceback (most recent call last):
File "get-contribs.py", line 96, in <module>
fec_files = filter(lambda x: x.endswith('.fec'),os.listdir(dname))
OSError: [Errno 2] No such file or directory: '1001015'
The file 1001015 is located in the directory /ruths/data/fec/efr. So how do I get access to those files from my directory?
You can specify the whole path when you enter a file name. For example, say you want to open a file “foo.txt” in the directory “/home/docs”. You could run the command:
where f is now a handle for your file. Alternatively, the command os.chdir from the module os changes the current working directory. The following snippet has the same effect as above: