[Tutor] Convert my .bat and .vbs to .py

Eric Walstad eric at ericwalstad.com
Thu Feb 15 20:58:11 CET 2007


Hey Mark,
Mark Bystry wrote:
> sh.copy('C:\testing_it.txt', 'D:\')

Also have a look at the os.path module.  Because you want these scripts
to work on both Linux and Windows, using os.path will let you avoid
writing platform specific code to handle your slashes.

For example:
import os
path_parts_list = ['C:', 'testing_it.txt']

Now, os.path.join will join those path parts together with whatever is
appropriate for the OS you are running on:

os.path.join(path_parts_list)

This should give you:
'c:\testing_it.txt' on Windows and
'c:/testing_it.txt' on Linux (which doesn't make sense, but demonstrates
how os.path can handle your os-specific slashes for you).

There are lots of helpful path related built-ins:
<http://docs.python.org/lib/module-os.path.html>


More information about the Tutor mailing list