Opinion on best practice...

Terry Reedy tjreedy at udel.edu
Tue Feb 5 08:56:39 CET 2013


On 2/4/2013 11:14 PM, Anthony Correia wrote:
> I need to pick up a language that would cover the Linux platform.  I use Powershell for a scripting language on the Windows side of things.  Very simple copy files script.  Is this the best way to do it?
>
> import os
>
>      objdir = ("C:\\temp2")
>      colDir = os.listdir(objdir)
>      for f in colDir:
>          activefile = os.path.join(objdir + "\\" + f)
>          print ("Removing " + activefile + " from " + objdir)
>          os.remove(activefile)
>
> In Powershell I would just do:
>
> $colDir = gci -path "c:\temp2"
> ForEach($file in $colDir)

Python comes with a shutil module with multiple copy functions.


-- 
Terry Jan Reedy




More information about the Python-list mailing list