Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38160
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-02-04 20:23 -0800 |
| Message-ID | <b93e47a7-9338-4a55-a81f-d6bb595fd8ab@googlegroups.com> (permalink) |
| Subject | Best Practice Question |
| From | Anthony Correia <akcorreia@gmail.com> |
Just started learning Python. I just wrote a simple copy files script. I use Powershell now as my main scripting language but I wanted to extend into the linux platform as well. 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 do this:
$colDir = gci -path "c:\temp2"
$objDir = "C:\temp3"
ForEach($file in $colDir){
#.Fullname lists the directory and filename together. No need to do a join
#beforehand.
Copy-item $file.fullname -destination $objDir
}
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Best Practice Question Anthony Correia <akcorreia@gmail.com> - 2013-02-04 20:23 -0800 Re: Best Practice Question Dave Angel <davea@davea.name> - 2013-02-05 06:52 -0500
csiph-web