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="\\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’, ‘\\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="\\\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="\\D:\Spare Parts\Main.csv"
I am getting the same error.
IOError: (2, ‘No such file or directory’, ‘\\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.


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

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

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


file="//$/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'\\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


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

1 Like