About Python isdir data processing

Asked 2 years ago, Updated 2 years ago, 23 views

I have a question while using isdir.


# Enter the directory to check and hand it over to the program routine
# You have not yet set the turning part.
# Directory verification command entered (os.path.isdir)
def DS(dir):
    dirS = (str(raw_input("Select Your Directory which you want Scan(e.x. C ) : ")))
    dirE = os.path.isdir(str(dirS)):
        if dirE == True:
            print("Ready for Scan Drive: ", dirS)
        else:
            print("It is not Drive or your system doesn't have ", dirS, "Drive.")

The drive data received in the str(raw_input()) portion above was referred to as dirS. And we processed it with IF and ELSE statements by checking the existence of dir entered below.

By the way,

dirE = os.path.iddir(str(dirS))

Of course, I got an error when I typed it.

How can I transfer the value entered from dirS to isdir? T.T

python isdir

2022-09-22 15:04

1 Answers

Because os.path.isdir is not enabled

You cannot write a colon, such as dirE = os.path.isdir(dirS):.

dirE = os.path.isdir(dirS)
 if dirE == True:
    print("Ready for Scan Drive: ", dirS)
else:
    print("It is not Drive or your system doesn't have ", dirS, "Drive.")

If you remove the colon like this and pull the indent on the code below one by one, it will work normally.


2022-09-22 15:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.