0

I'm trying to write a program that will detect whether or not a drive exists. The code I have works, but I get an annoying pop-up from PythonW.exe when I run the program.

import os, time, shutil, datetime, re, warnings

while True:     #Loop until you close program
    allDrives = re.findall(r"[A-Z]+:.*$",os.popen("mountvol /").read(),re.MULTILINE)    #Find all drive letters
    print("Found drives.")

    for c in range(len(allDrives)):
        drive = allDrives[c]
        if os.path.isdir(drive) == False:
            print("Hangs here.")
            pass
        else:
            print(os.path.isdir(drive))
            pathStr = drive + 'logs\\'
            pathBool = os.path.exists(pathStr)  #Check to see if 'logs' folder is visible

I've tried using os.path.exists(path) instead of os.path.isdir(path), but that doesn't work either. I just want a way to disable the pop-up.

  • Check by letter, such as 'C', 'G', etc? Must the check include networked drives that might not be available? – Bill Bell Jul 14 '17 at 16:40
  • See https://stackoverflow.com/a/4790310/131187 – Bill Bell Jul 14 '17 at 16:57
  • I'm trying to make the program in such a way that it doesn't matter what computer you connect it to. A lot of the computers I need to run it on will have a lot of drives of varying numbers. Where the 'logs' folder might be found will vary based on that. Plus, some of the computers might have drives mapped all the way to 'Z:'. Also, even if I check by letter, I'll still run into the same error when I get to the drive in question. – Amaryllis Ninja Jul 14 '17 at 16:59
  • I think that answer I pointed to does what you need. – Bill Bell Jul 14 '17 at 17:03

0 Answers0