Python Forum
os.path.isdir(<whatever>) returns always True
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
os.path.isdir(<whatever>) returns always True
#4
Look carefully at your code. I have a feeling that you've been looking at it so long, you've developed tunnel vision, and are skipping over parts of what's happening.

(Dec-04-2018, 02:22 PM)Fabrizio Wrote:
if (os.path.isdir(source_dir)):
    print "source directory not found"

Here, let me help rewrite it for you:
source_dir = "/literally_nowhere"
directory_exists = os.path.isdir(source_dir)

if directory_exists:
    print("It doesn't exist")
Or, to break it down even further:
if False:
    print("It's True")
Obviously the else part is running: the condition you're checking is False.
Reply


Messages In This Thread
RE: os.path.isdir(<whatever>) returns always True - by nilamo - Dec-04-2018, 04:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,217 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  path.exists returning True when it shouldn't natha18 0 1,505 Sep-21-2020, 01:04 PM
Last Post: natha18
  Recursive function returns None, when True is expected akar 0 3,396 Sep-07-2020, 07:58 PM
Last Post: akar
  Returning True or False vs. True or None trevorkavanaugh 6 9,268 Apr-04-2019, 08:42 AM
Last Post: DeaD_EyE
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,775 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908
  why the generator expression after IF always returns True HenryJ 1 2,724 Feb-13-2018, 07:14 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020