I'm trying to write a script that will go to a host and list all of its shares.

So far, in my searching, it seems that I need to include a top level share name.

For example:

os.listdir('\\\\1.2.3.4\\')

doesn't seem to work, but

os.listdir('\\\\1.2.3.4\\share\\')

will work.

As a bit of a work-around, I was thinking of first running "net view" and then taking the output from that to input the share name. The only problem I have is I'm not sure how to handle the net view output.

Share name    Type  Used as  Comment

--------------------------------------------------------------
Data          Disk
Data2         Disk
My Docs       Disk
Users         Disk
The command completed successfully.

I thought of using REGEX to look for the lines that contain the work "Disk", but I don't know how to separate the string at that point to get only the share name.

Any tips would be appreciated, or if you know of a better way I can accomplish this, I'm open to suggestions.

Thanks.

This way you can find those names, just replace your action in place of print.

inp="""Share name    Type  Used as  Comment

--------------------------------------------------------------
Data          Disk
Data2         Disk
My Docs       Disk
Users         Disk
The command completed successfully."""

for line in inp.splitlines():
    if line[14:18]=='Disk': print line[0:13].rstrip()

"""Output:
Data         
Data2        
My Docs      
Users        
"""

Edited 6 Years Ago by pyTony: Change to fixed length fields

This article has been dead for over six months. Start a new discussion instead.