OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

python os.path.exists reports False when files is there

  • Thread starter Thread starter speedyrazor
  • Start date Start date
S

speedyrazor

Guest
Hi have an application which is sometimes reporting that a file does not exist even when it does, I am using os.path.exists and the file is on a mounted network share. I am on OSX Yosemite, python 2.7.9 and I have access rights to the file. Here's the weird thing. The first command below reports False, I then run it again but change one of the characters in the file name to lowercase (TestVendorid_VerifyLog.txt), run it again and it reports True! Then run it again with the upper case again (TestVendorId_VerifyLog.txt) and it reports True! What is going on? This is quite consistent, in that it returns True most of the time, but then all of a sudden return False, then I can repeat the below exercise.

Code:
>>> import os
>>> os.path.exists("/Volumes/platform-deliveries-103_1/TEST/TestVendorId.itmsp/TestVendorId_VerifyLog.txt")
False
>>> os.path.exists("/Volumes/platform-deliveries-103_1/TEST/TestVendorId.itmsp/TestVendorid_VerifyLog.txt")
True
>>> os.path.exists("/Volumes/platform-deliveries-103_1/TEST/TestVendorId.itmsp/TestVendorId_VerifyLog.txt")
True
>>>

UPDATE 1:

When it is reporting True, I ran this:

Code:
>>> os.stat("/Volumes/platform-deliveries-103_1/TEST/TestVendorId.itmsp/TestVendorId_VerifyLog.txt")
posix.stat_result(st_mode=33216, st_ino=5351561660274954203, st_dev=771751953L, st_nlink=1, st_uid=504, st_gid=20, st_size=38552, st_atime=1428492003, st_mtime=1428589374, st_ctime=1428589374)

UPDATE 2:

OK, I can now repeat this and it is definitely a cache thing. I delete the file TestVendorId_VerifyLog.txt on my local Mac, then recreate the file on another workstation (this file is on a network share) I then get False on my Mac. If I change a letter in the file name of the os.path.exists command, it seems to make os.path.exists take a harder look for the file and finds it. So what I need is a 'Refresh Finder' command in python just prior to running the command.
<p>Hi have an application which is sometimes reporting that a file does not exist even when it does, I am using os.path.exists and the file is on a mounted network share. I am on OSX Yosemite, python 2.7.9 and I have access rights to the file. Here's the weird thing. The first command below reports <code>False</code>, I then run it again but change one of the characters in the file name to lowercase (<code>TestVendorid_VerifyLog.txt</code>), run it again and it reports <code>True</code>! Then run it again with the upper case again (<code>TestVendorId_VerifyLog.txt</code>) and it reports <code>True</code>! What is going on? This is quite consistent, in that it returns <code>True</code> most of the time, but then all of a sudden return <code>False</code>, then I can repeat the below exercise.</p>

<pre><code>>>> import os
>>> os.path.exists("/Volumes/platform-deliveries-103_1/TEST/TestVendorId.itmsp/TestVendorId_VerifyLog.txt")
False
>>> os.path.exists("/Volumes/platform-deliveries-103_1/TEST/TestVendorId.itmsp/TestVendorid_VerifyLog.txt")
True
>>> os.path.exists("/Volumes/platform-deliveries-103_1/TEST/TestVendorId.itmsp/TestVendorId_VerifyLog.txt")
True
>>>
</code></pre>

<p>UPDATE 1:</p>

<p>When it is reporting <code>True</code>, I ran this:</p>

<pre><code>>>> os.stat("/Volumes/platform-deliveries-103_1/TEST/TestVendorId.itmsp/TestVendorId_VerifyLog.txt")
posix.stat_result(st_mode=33216, st_ino=5351561660274954203, st_dev=771751953L, st_nlink=1, st_uid=504, st_gid=20, st_size=38552, st_atime=1428492003, st_mtime=1428589374, st_ctime=1428589374)
</code></pre>

<p>UPDATE 2:</p>

<p>OK, I can now repeat this and it is definitely a cache thing. I delete the file TestVendorId_VerifyLog.txt on my local Mac, then recreate the file on another workstation (this file is on a network share) I then get False on my Mac. If I change a letter in the file name of the os.path.exists command, it seems to make os.path.exists take a harder look for the file and finds it. So what I need is a 'Refresh Finder' command in python just prior to running the command.</p>
 

Latest posts

Top