4

I am trying to test if a file exists on the network drive using os.path.isfile however it returns false even when the file is there. Any ideas why this might be or any other methods I could use to check for this file?

I am using Python2.7 and Windows10

This returns true as it should:

import os

if os.path.isfile("C:\test.txt"):
    print "Is File"
else:
    print "Is Not File"

This returns false even though the file exists:

import os

if os.path.isfile("Q:\test.txt"):
    print "Is File"
else:
    print "Is Not File"
Tom Carroll
  • 252
  • 8
  • 19

1 Answers1

6

From python https://docs.python.org/2/library/os.path.html:

The os.path module is always the path module suitable for the operating system Python is running on, and therefore usable for local paths

Trying using the full UNC path instead of the mapped drive.

import os

if os.path.isfile(r"\\full\uncpath\test.txt"):
    print "Is File"
else:
    print "Is Not File"
nullByteMe
  • 6,141
  • 13
  • 62
  • 99