Is there a better way of listing Windows shares other than using"os.listdir"

Discussion in 'Python' started by Doran_Dermot@emc.com, Dec 30, 2004.

  1. Guest

    Hi All,

    I'm currently using "os.listdir" to obtain the contents of some slow Windows
    shares. I think I've seen another way of doing this using the win32 library
    but I can't find the example anymore.

    My main problem with using "os.listdir" is that it hangs my gui application.
    The tread running the "os.listdir" appears to block all other threads when
    it calls this function.

    Any ideas, comments or suggestions?

    Thanks in advance,

    Dermot.
     
    , Dec 30, 2004
    #1
    1. Advertisements

  2. David Bolen Guest

    Re: Is there a better way of listing Windows shares other than using "os.listdir"

    writes:

    > I'm currently using "os.listdir" to obtain the contents of some slow Windows
    > shares. I think I've seen another way of doing this using the win32 library
    > but I can't find the example anymore.


    Do you want the list of files on the shares or the list of shares
    itself? If the files, you can use something like FindFiles, but I
    don't expect it to be that much faster just to obtain directory names
    (likely the overhead is on the network).

    If you just want a list of shares, you could use NetUseEnum, which
    should be pretty speedy.

    (FindFiles is wrapped by win32api, and NetUseEnum by win32net, both parts
    of the pywin32 package)

    Here's a short example of displaying equivalent output to the "net
    use" command:

    - - - - - - - - - - - - - - - - - - - - - - - - -
    import win32net

    status = {0 : 'Ok',
    1 : 'Paused',
    2 : 'Disconnected',
    3 : 'Network Error',
    4 : 'Connected',
    5 : 'Reconnected'}

    resume = 0
    while 1:
    (results, total, resume) = win32net.NetUseEnum(None, 1, resume)
    for use in results:
    print '%-15s %-5s %s' % (status.get(use['status'], 'Unknown'),
    use['local'],
    use['remote'])
    if not resume:
    break
    - - - - - - - - - - - - - - - - - - - - - - - - -

    Details on the the arguments to NetUseEnum can be found in MSDN (with
    any pywin32 specifics in the pywin32 documentation).

    > My main problem with using "os.listdir" is that it hangs my gui application.
    > The tread running the "os.listdir" appears to block all other threads when
    > it calls this function.


    Yes, for a GUI you need to keep your main GUI thread always responsive
    (e.g., don't do any blocking operations).

    There are a number of alternatives to handling a long processing task
    in a GUI application, dependent on both the operation and toolkit in
    use. For wxPython, http://wiki.wxpython.org/index.cgi/LongRunningTasks
    covers several of the options (and the theory behind them is generally
    portable to other toolkits although implementation will change).

    -- David
     
    David Bolen, Dec 30, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kai
    Replies:
    1
    Views:
    391
  2. kai
    Replies:
    0
    Views:
    384
  3. kai
    Replies:
    0
    Views:
    327
  4. kai
    Replies:
    0
    Views:
    329
  5. Peter Bencsik
    Replies:
    2
    Views:
    899
Loading...

Share This Page