With a little side of applesauce...

Monday, January 29, 2007

Running Python scripts with cscript

You can use Python to work with COM objects by:

1. Using the .pys extension

2. Calling the script with cscript.exe

c:\scripts> cscript listfiles.pys

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

#.newsrc-dribble#
104.wav
124.txt
AUTOEXEC.BAT
boot.ini
cert.csr
COMLOG.txt
CONFIG.SYS

Here is the code for listfiles.pys:

fso = WScript.CreateObject(”Scripting.FileSystemObject”)
files = fso.GetFolder(”c:\\”).Files

for file in files:
print file.name

Borrowed from Windows Scripting and Objects by Brian Knittel.

No comments: