Why os.path.isdir() or os.path.existis() always return FalseHow to return multiple values from a function?Python join: why is it string.join(list) instead of list.join(string)?Why is __init__() always called after __new__()?Why are Python lambdas useful?Why can't Python parse this JSON data?Why use pip over easy_install?Why is reading lines from stdin much slower in C++ than Python?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?Why does “not(True) in [False, True]” return False?errors with Elif expected indented block

Word for being out at night during curfew

Usefulness of complex chord names?

Front derailleur hard to move due to gear cable angle

Can 'sudo apt-get remove [write]' destroy my Ubuntu?

What's the word for the soldier salute?

Should these notes be played as a chord or one after another?

Extracting sublists that contain similar elements

Understanding integration over Orthogonal Group

Is taking modulus on both sides of an equation valid?

Why doesn't Rocket Lab use a solid stage?

Can I use my laptop, which says 100-240V, in the USA?

Why in a Ethernet LAN, a packet sniffer can obtain all packets sent over the LAN?

Why was Endgame Thanos so different than Infinity War Thanos?

Reaction of borax with NaOH

Meaning of「〜てみたいと思います」

How do I tell my supervisor that he is choosing poor replacements for me while I am on maternity leave?

How did Thanos not realise this had happened at the end of Endgame?

Extrude the faces of a cube symmetrically along XYZ

How to cope with regret and shame about not fully utilizing opportunities during PhD?

For the erase-remove idiom, why is the second parameter necessary which points to the end of the container?

How can I answer high-school writing prompts without sounding weird and fake?

Why was Thor doubtful about his worthiness to Mjolnir?

Make all the squares explode

Is the schwa sound consistent?



Why os.path.isdir() or os.path.existis() always return False


How to return multiple values from a function?Python join: why is it string.join(list) instead of list.join(string)?Why is __init__() always called after __new__()?Why are Python lambdas useful?Why can't Python parse this JSON data?Why use pip over easy_install?Why is reading lines from stdin much slower in C++ than Python?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?Why does “not(True) in [False, True]” return False?errors with Elif expected indented block






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am using a function to test if a directory entered by user is valid or not. The user input doesn't go to the file name, it only goes to the folder name e.g. "C:/Users/username/Desktop/folder". So I wrote the following function to get the path/directory:



def get_path():
while True:
file_path = input("Please enter file path (up to folder level); q to quit:> ")
print(repr(file_path))
if os.path.isdir(file_path):
return file_path
elif file_path.lower() == 'q':
sys.exit()
else:
print("The path you entered is invalid.")
continue


However, it always shows The path you entered is invalid. even though the path/string I entered is valid when running the os.path.isdir() in cmd.



Running the function on my Win10 cmd generates the following results



>>> import sys
>>> import os
>>> import pathlib
>>> def get_path():
... while True:
... file_path = input("Please enter file path (up to folder level); q to quit:> ")
... print(repr(file_path))
... if os.path.isdir(file_path):
... return file_path
... elif file_path.lower() == 'q':
... sys.exit()
... else:
... print("The path you entered is invalid.")
... continue
...
>>> path = get_path()
Please enter file path (up to folder level); q to quit:> "C:/Users/myname/Desktop/"
'"C:/Users/myname/Desktop/"'
The path you entered is invalid.
Please enter file path (up to folder level); q to quit:> "C:/Users/myname/Desktop/randomprojects"
'"C:/Users/myname/Desktop/randomprojects"'
The path you entered is invalid.
Please enter file path (up to folder level); q to quit:>









share|improve this question



















  • 1





    Please share the complete log where you get the error.

    – Abhiram Satputé
    Mar 23 at 12:02






  • 1





    Can you share the path that you are entering? The code seems to be working fine on my side. isdir will not be able to find the file, it returns true only if the named directory is found. To have either of the file or folder name to be found, you should try os.path.exists only.

    – Abhiram Satputé
    Mar 23 at 12:46







  • 1





    You don't have to enter the path in " " , just type plain C:/Users/myname/Desktop/randomprojects as the input, the rest will be handled automatically.

    – Abhiram Satputé
    Mar 23 at 12:53







  • 1





    Huh...thanks a lot..I thought it requires "" to enter it. Shame on me. Have a nice weekend! I really appreciate it.

    – commentallez-vous
    Mar 23 at 12:56






  • 1





    haha, glad to help. Cheers!

    – Abhiram Satputé
    Mar 23 at 13:02

















0















I am using a function to test if a directory entered by user is valid or not. The user input doesn't go to the file name, it only goes to the folder name e.g. "C:/Users/username/Desktop/folder". So I wrote the following function to get the path/directory:



def get_path():
while True:
file_path = input("Please enter file path (up to folder level); q to quit:> ")
print(repr(file_path))
if os.path.isdir(file_path):
return file_path
elif file_path.lower() == 'q':
sys.exit()
else:
print("The path you entered is invalid.")
continue


However, it always shows The path you entered is invalid. even though the path/string I entered is valid when running the os.path.isdir() in cmd.



Running the function on my Win10 cmd generates the following results



>>> import sys
>>> import os
>>> import pathlib
>>> def get_path():
... while True:
... file_path = input("Please enter file path (up to folder level); q to quit:> ")
... print(repr(file_path))
... if os.path.isdir(file_path):
... return file_path
... elif file_path.lower() == 'q':
... sys.exit()
... else:
... print("The path you entered is invalid.")
... continue
...
>>> path = get_path()
Please enter file path (up to folder level); q to quit:> "C:/Users/myname/Desktop/"
'"C:/Users/myname/Desktop/"'
The path you entered is invalid.
Please enter file path (up to folder level); q to quit:> "C:/Users/myname/Desktop/randomprojects"
'"C:/Users/myname/Desktop/randomprojects"'
The path you entered is invalid.
Please enter file path (up to folder level); q to quit:>









share|improve this question



















  • 1





    Please share the complete log where you get the error.

    – Abhiram Satputé
    Mar 23 at 12:02






  • 1





    Can you share the path that you are entering? The code seems to be working fine on my side. isdir will not be able to find the file, it returns true only if the named directory is found. To have either of the file or folder name to be found, you should try os.path.exists only.

    – Abhiram Satputé
    Mar 23 at 12:46







  • 1





    You don't have to enter the path in " " , just type plain C:/Users/myname/Desktop/randomprojects as the input, the rest will be handled automatically.

    – Abhiram Satputé
    Mar 23 at 12:53







  • 1





    Huh...thanks a lot..I thought it requires "" to enter it. Shame on me. Have a nice weekend! I really appreciate it.

    – commentallez-vous
    Mar 23 at 12:56






  • 1





    haha, glad to help. Cheers!

    – Abhiram Satputé
    Mar 23 at 13:02













0












0








0








I am using a function to test if a directory entered by user is valid or not. The user input doesn't go to the file name, it only goes to the folder name e.g. "C:/Users/username/Desktop/folder". So I wrote the following function to get the path/directory:



def get_path():
while True:
file_path = input("Please enter file path (up to folder level); q to quit:> ")
print(repr(file_path))
if os.path.isdir(file_path):
return file_path
elif file_path.lower() == 'q':
sys.exit()
else:
print("The path you entered is invalid.")
continue


However, it always shows The path you entered is invalid. even though the path/string I entered is valid when running the os.path.isdir() in cmd.



Running the function on my Win10 cmd generates the following results



>>> import sys
>>> import os
>>> import pathlib
>>> def get_path():
... while True:
... file_path = input("Please enter file path (up to folder level); q to quit:> ")
... print(repr(file_path))
... if os.path.isdir(file_path):
... return file_path
... elif file_path.lower() == 'q':
... sys.exit()
... else:
... print("The path you entered is invalid.")
... continue
...
>>> path = get_path()
Please enter file path (up to folder level); q to quit:> "C:/Users/myname/Desktop/"
'"C:/Users/myname/Desktop/"'
The path you entered is invalid.
Please enter file path (up to folder level); q to quit:> "C:/Users/myname/Desktop/randomprojects"
'"C:/Users/myname/Desktop/randomprojects"'
The path you entered is invalid.
Please enter file path (up to folder level); q to quit:>









share|improve this question
















I am using a function to test if a directory entered by user is valid or not. The user input doesn't go to the file name, it only goes to the folder name e.g. "C:/Users/username/Desktop/folder". So I wrote the following function to get the path/directory:



def get_path():
while True:
file_path = input("Please enter file path (up to folder level); q to quit:> ")
print(repr(file_path))
if os.path.isdir(file_path):
return file_path
elif file_path.lower() == 'q':
sys.exit()
else:
print("The path you entered is invalid.")
continue


However, it always shows The path you entered is invalid. even though the path/string I entered is valid when running the os.path.isdir() in cmd.



Running the function on my Win10 cmd generates the following results



>>> import sys
>>> import os
>>> import pathlib
>>> def get_path():
... while True:
... file_path = input("Please enter file path (up to folder level); q to quit:> ")
... print(repr(file_path))
... if os.path.isdir(file_path):
... return file_path
... elif file_path.lower() == 'q':
... sys.exit()
... else:
... print("The path you entered is invalid.")
... continue
...
>>> path = get_path()
Please enter file path (up to folder level); q to quit:> "C:/Users/myname/Desktop/"
'"C:/Users/myname/Desktop/"'
The path you entered is invalid.
Please enter file path (up to folder level); q to quit:> "C:/Users/myname/Desktop/randomprojects"
'"C:/Users/myname/Desktop/randomprojects"'
The path you entered is invalid.
Please enter file path (up to folder level); q to quit:>






python path directory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 12:51







commentallez-vous

















asked Mar 23 at 12:00









commentallez-vouscommentallez-vous

405213




405213







  • 1





    Please share the complete log where you get the error.

    – Abhiram Satputé
    Mar 23 at 12:02






  • 1





    Can you share the path that you are entering? The code seems to be working fine on my side. isdir will not be able to find the file, it returns true only if the named directory is found. To have either of the file or folder name to be found, you should try os.path.exists only.

    – Abhiram Satputé
    Mar 23 at 12:46







  • 1





    You don't have to enter the path in " " , just type plain C:/Users/myname/Desktop/randomprojects as the input, the rest will be handled automatically.

    – Abhiram Satputé
    Mar 23 at 12:53







  • 1





    Huh...thanks a lot..I thought it requires "" to enter it. Shame on me. Have a nice weekend! I really appreciate it.

    – commentallez-vous
    Mar 23 at 12:56






  • 1





    haha, glad to help. Cheers!

    – Abhiram Satputé
    Mar 23 at 13:02












  • 1





    Please share the complete log where you get the error.

    – Abhiram Satputé
    Mar 23 at 12:02






  • 1





    Can you share the path that you are entering? The code seems to be working fine on my side. isdir will not be able to find the file, it returns true only if the named directory is found. To have either of the file or folder name to be found, you should try os.path.exists only.

    – Abhiram Satputé
    Mar 23 at 12:46







  • 1





    You don't have to enter the path in " " , just type plain C:/Users/myname/Desktop/randomprojects as the input, the rest will be handled automatically.

    – Abhiram Satputé
    Mar 23 at 12:53







  • 1





    Huh...thanks a lot..I thought it requires "" to enter it. Shame on me. Have a nice weekend! I really appreciate it.

    – commentallez-vous
    Mar 23 at 12:56






  • 1





    haha, glad to help. Cheers!

    – Abhiram Satputé
    Mar 23 at 13:02







1




1





Please share the complete log where you get the error.

– Abhiram Satputé
Mar 23 at 12:02





Please share the complete log where you get the error.

– Abhiram Satputé
Mar 23 at 12:02




1




1





Can you share the path that you are entering? The code seems to be working fine on my side. isdir will not be able to find the file, it returns true only if the named directory is found. To have either of the file or folder name to be found, you should try os.path.exists only.

– Abhiram Satputé
Mar 23 at 12:46






Can you share the path that you are entering? The code seems to be working fine on my side. isdir will not be able to find the file, it returns true only if the named directory is found. To have either of the file or folder name to be found, you should try os.path.exists only.

– Abhiram Satputé
Mar 23 at 12:46





1




1





You don't have to enter the path in " " , just type plain C:/Users/myname/Desktop/randomprojects as the input, the rest will be handled automatically.

– Abhiram Satputé
Mar 23 at 12:53






You don't have to enter the path in " " , just type plain C:/Users/myname/Desktop/randomprojects as the input, the rest will be handled automatically.

– Abhiram Satputé
Mar 23 at 12:53





1




1





Huh...thanks a lot..I thought it requires "" to enter it. Shame on me. Have a nice weekend! I really appreciate it.

– commentallez-vous
Mar 23 at 12:56





Huh...thanks a lot..I thought it requires "" to enter it. Shame on me. Have a nice weekend! I really appreciate it.

– commentallez-vous
Mar 23 at 12:56




1




1





haha, glad to help. Cheers!

– Abhiram Satputé
Mar 23 at 13:02





haha, glad to help. Cheers!

– Abhiram Satputé
Mar 23 at 13:02












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55313506%2fwhy-os-path-isdir-or-os-path-existis-always-return-false%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55313506%2fwhy-os-path-isdir-or-os-path-existis-always-return-false%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript