[Samba] python: listing samba shares

Igor Katson descentspb at gmail.com
Sun Aug 16 13:18:40 MDT 2009


Ricardo Jorge wrote:
> Just try using the regular python os.listdir()
>
> Use this code:
>
> .....
>
>         ctr = srvsvc.NetShareInfoCtr()
>         shares = conn.NetShareEnumAll(u'localhost', ctr, 0, 0)
>
>         print "\n\n============"
>         print "There are " + str(shares[0].ctr.count) + " shares"
>         print "============\n"
>
>         for i in range(0, shares[0].ctr.count):
>                 share_info = info = conn.NetShareGetInfo(u'localhost',
> shares[0].ctr.array[i].name, 2)
>                 print share_info.name + "\t" + share_info.path + "\t "
> + share_info.comment
>
>                 if len(share_info.path) > 0:
>                         try:
>                                 print os.listdir(share_info.path)
>                         except:
>                                 pass
>
>         print "\n\n"
>
> .....
>
> Just note that share_info.path is returning the path name "windows
> style" (c:\blabla) so the dir listing will (most likely) fail. You'll
> have to convert this if required.
>   
I would like to list remote samba shares contents (most of which are 
windows machines), not the local ones. So os.listdir() cannot help here.


More information about the samba mailing list