file backup in windows

Tim Golden Tim.Golden at viacom-outdoor.co.uk
Wed Nov 22 07:43:19 EST 2006


| I am sorry I am providing the code i used as it is. Being newbee to
| programming I have tinkerd with various options i found on the net.

Thanks. That makes it a lot easier

[... snip ...]
| source = outlook_path
| #source = outlook_path +'\\*'
| print source

[...]

| win32file.CopyFile (source, target, 1)

| ---------
| output
| ----------
| C:\Documents and Settings\060577\Local Settings\Application
| Data\Microsoft\Outlook\*
| Successfully created directory D:\temp\outlook1_2006-11-22_17.41.54
| 
| Traceback (most recent call last):
|   File "C:\Documents and
| Settings\060577\kk\source_code\py\Mypy\pywin32test.py", line 34, in
| <module>
|     win32file.CopyFile (source, target, 1)
| error: (123, 'CopyFile', 'The filename, directory name, or 
| volume label
| syntax is incorrect.')


Fairly certain that the win32file.CopyFile API call doesn't
handle wildcards. You have to do that yourself. (I could be wrong).

Quick check:
<dump>
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys
>>> import win32file
>>>
>>> os.chdir ("c:/temp")
>>> os.mkdir ("backup")
>>> win32file.CopyFile ("*.txt", "backup", 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
pywintypes.error: (123, 'CopyFile', 'The filename, directory name, or
volume label syntax is incorrect.')
>>>
>>> win32file.CopyFile ("temp.txt", "backup", 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
pywintypes.error: (2, 'CopyFile', 'The system cannot find the file
specified.')
>>>
>>> win32file.CopyFile ("exists.txt", "backup", 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
pywintypes.error: (5, 'CopyFile', 'Access is denied.')
>>> win32file.CopyFile ("exists.txt", "backup/exists.txt", 1)
>>>

</dump>

Sure enough:

1) Wildcards give the error you had
2) Non-existent file gives a suitable messag
3) Existing filename to folder name only gives Access denied
4) Existing filename to folder name + filename copies ok.

Now, that only took about a minute to run through on the interpreter
and check, so hopefully that'll help you out next time: create a
small test case (without all the long path names). Find out what
CopyFile can or can't do and act accordingly.

If you haven't already, look at the glob module:

http://docs.python.org/lib/module-glob.html

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list