Python: Accessing Windows mapped network drive with known URL, but unknown drive letter

前端 未结 4 1379
南方客
南方客 2021-02-10 07:21

I am trying to write a Python script that can move and copy files on a remote Linux server. However, I can\'t assume that everyone running the script (on Windows) will have mapp

4条回答
  •  半阙折子戏
    2021-02-10 07:58

    Not a very elegant solution, but you could just try all the drives?

    From here:

    import win32api
    
    drives = win32api.GetLogicalDriveStrings()
    drives = drives.split('\000')[:-1]
    print drives
    

    Then you could use os.path.exists() on every drive:\var\SomeFile.txt until you find the right one.

提交回复
热议问题