[Tutor] Using os.path.walk across platforms

lumbricus@gmx.net lumbricus@gmx.net
Tue, 7 Aug 2001 21:41:15 +0200


On Tue, Aug 07, 2001 at 02:17:34PM -0500, Randy Waters wrote:
> Hello. I have an interesting little challenge. I need to copy files from
> an NT server to multiple Linux servers. The Python script needs to
> execute on a UNIX server. I am using ftplib and os.path.
> 
> My problem is that the standard 'LIST' in (ftplib) retrlines needs to be
> captured to a list so that I can check to see if a entry is a directory
> or not. If I were executing only on UNIX/Linux I could use os.path.walk
> without a problem, but I am trying to "walk" down an NT path from UNIX. 
> 
> This script:
> 
> #!/usr/bin/python
> 
> import os, string
> >from ftplib import FTP
> 
> def TheList(arg, dirname, names):
>         for name in names:
>                 print os.path.join(dirname, name)
>                 if os.path.isdir(name):
>                   print name + ' is a directory...'
> 
> def GetFiles():
>   session = FTP()
>   session.connect('myserver.domain.com', port=8282)
>   session.login()
>   os.path.walk(session.retrlines('LIST'), TheList, None)
>   session.close()
>   return
> 
> GetFiles()
> -------------------
> Returns this type of information:
> 
> dr-xr-xr-x   1 owner    group               0 Dec  7  2000 Co pack
> projects
> dr-xr-xr-x   1 owner    group               0 May 29 14:52 COA
> dr-xr-xr-x   1 owner    group               0 Aug  2  8:45 HANDLING
> -r-xr-xr-x   1 owner    group           12800 Nov  4  1996 INFRZPR2.DOC
> 
> -------------------
> 
> If I could test the 1st position for 'd' then I would know that I have
> to chdir and read down the tree. Using os.path.isdir does not work
> probably because I am running my script on a UNIX server logged into an
  ^^^^^^^^
  Have you tried it? I can't right now, but i don't see a 
  problem (or am i missing something?)
  
> NT server.
> 
> If anyone has any ideas I would appreciate it. Thank you and what a
> great language!
> 

Greetings J"o! :-)

-- 
To be sure of hitting the target, shoot first and, whatever you hit,
call it the target.