how to get os.system () call to cooperate on Windows

Gabriel Genellina gagsl-py2 at
Wed Oct 28 01:48:36 CET 2009

En Tue, 27 Oct 2009 10:55:09 -0300, TerryP <bigboss1964 at>

> On Oct 26, 10:00 am, Anthra Norell <anthra.nor... at> wrote:
>> The function "os.system
>> ('copy file_name directory_name')" turns out doesn't do anything except
>> flashing a DOS command window for half a second. So my question is: How
>> can one copy files on the OS level?
> Under a Windows system the built in command, copy, is a pile of crap
> and xcopy is not much fun; you need to screw with it at the command
> prompt to find the exact usage.

Uh... well, not because you don't know the command syntax it becomes a
pile of crap...

> The formal way to copy files on the 'OS level' is by way of a system
> call. I believe under Windows NT, this would be the CopyFile family;
> using that through cctypes doesn't sound like fun.

It's as simple as this:

   from ctypes import windll
CopyFile = windll.kernel32.CopyFileA
CopyFile("d:\\temp\\old.txt", "d:\\temp\\new.txt", True)

Gabriel Genellina

More information about the Python-list mailing list