Reading CSV file from other computer in network

Hello, I am trying to read csv file from a server computer using the following path.
file="\192.168.209.191\D:\Spare Parts\Main.csv"
Folder,file names and IP address are correct.
But I get this error- IOError: (2, ‘No such file or directory’, ‘\192.168.209.191\D:\Spare Parts\Main.csv’)
May I know what is the correct format to use.
Thank you.

OK I don’t know if your post swallowed an extra slash, but my first guess is that you need a double slash for the UNC path to the target computer. EG

file="\\192.168.209.191\D:\Spare Parts\Main.csv"

(Note I had to put 4 slashes to get 2 slashes to show up in my reply)

1 Like

Peter, I tried with 2 slashes as well.
file="\192.168.209.191\D:\Spare Parts\Main.csv"
I am getting the same error.
IOError: (2, ‘No such file or directory’, ‘\192.168.209.191\D:\Spare Parts\Main.csv’)

You can’t put drive letters with colons in a UNC path. You must create a share name in the target computer. If the user accessing the target has admin rights, you may be able to use the C$ and similar admin shares.

2 Likes

Also, the backslash is an escape character in many programming languages. So you need two for every one.

file="\\\\192.168.209.191\\shareName\\Spare Parts\\Main.csv"

Or, just replace them with forward slashes.
file="//192.168.209.191/shareName/Spare Parts/Main.csv"

2 Likes

file="//192.168.209.191/D$/Spare Parts/Main.csv"
This worked.
Thank you :slight_smile:

1 Like

Alternatively, use the r prefix. Makes things a bit cleaner. Not to mention it’s easy miss one like in your example :wink:

file=r'\192.168.209.191\shareName\Spare Parts\Main.csv'

String literals may optionally be prefixed with a letter ‘r’ or ‘R’; such strings are called raw strings and use different rules for interpreting backslash escape sequences

https://python.readthedocs.io/en/v2.7.2/reference/lexical_analysis.html

7 Likes

See? And that’s a strike against using them right there…

1 Like