Python Forum
os.path.exists apparently doesn't always work!
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
os.path.exists apparently doesn't always work!
#1
This code should sense that there is no data sub-directory,
and create it, but it doesn't on windows 7, but I swear it worked in the past.

I guess i could use shutil

import os

datapath = f'{os.path.abspath(os.getcwd())}\\data'
if not os.path.exists(datapath):
    print('creating path')
    os.makedirs(datapath)
else:
    print('path exists')
Reply
#2
Nevermind, i didn't have the not (to reverse results)
I stared at this for a while, and never saw it (I edited my post and added it!)

I thank the forum for being my cardboard programmer!
Reply
#3
All things come to those who stare at it.  Angel
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PIP doesn't work YKR 1 700 Mar-28-2025, 02:10 PM
Last Post: snippsat
  I'm trying to install python 3.11.11 on windows 10 - it doesn't work Petonique 2 1,930 Feb-04-2025, 05:42 PM
Last Post: snippsat
  os.path.exists fails with accented characters glenndrives 11 2,854 Sep-03-2024, 05:30 PM
Last Post: glenndrives
  Extending list doesn't work as expected mmhmjanssen 2 1,414 May-09-2024, 05:39 PM
Last Post: Pedroski55
  Why wont this path work one way, but will the other way? cubangt 2 1,341 Sep-01-2023, 04:14 PM
Last Post: cubangt
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 1,945 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 3,571 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  color code doesn't work harryvl 1 1,865 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  client.get_all_tickers() Doesn't work gerald 2 2,624 Jun-16-2022, 07:59 AM
Last Post: gerald
  pip doesn't work after Python upgrade Pavel_47 10 6,843 May-30-2022, 03:31 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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