By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

file backup in windows

P: n/a
Hi ALL,

I am a newbee programmer and started of with python recently. I am
trying write a script which backups outlook (.pst ) files everytime I
shutdown my system. I have writtern following code after some findings
on net. My .pst file path is as follows

" c:\documents and settings\060577\Local Settings\Application
Data\Microsoft\Outlook "
where 060577 represents username. I want my script to identigy the user
logged in and go to the resp outlook folder or should be able to read
outlook store directory path from registry and the copy the files to
the desired path.

---------------------------------------------------
how can i make the following code work, I have probelm with filepath
declaration.
---------------------------------------------------
import os, shutil
filepath = ' C:\\Documents and Settings\\060577\\Local
Settings\\Application Data\\Microsoft\\Outlook\\* '
backup = ' D:\\temp\\outlook '
os.system ("xcopy /s %s %s" % (filepath, backup))
-----------------------------------------
Thank you,
Kk

Nov 22 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
k.i.n.g. wrote:
how can i make the following code work, I have probelm with filepath
declaration.
http://effbot.org/pyfaq/tutor-i-need...at-should-i-do

</F>

Nov 22 '06 #2

P: n/a
k.i.n.g. wrote:
Hi ALL,

I am a newbee programmer and started of with python recently. I am
trying write a script which backups outlook (.pst ) files everytime I
shutdown my system. I have writtern following code after some findings
on net. My .pst file path is as follows

" c:\documents and settings\060577\Local Settings\Application
Data\Microsoft\Outlook "
where 060577 represents username. I want my script to identigy the user
logged in and go to the resp outlook folder or should be able to read
outlook store directory path from registry and the copy the files to
the desired path.

---------------------------------------------------
how can i make the following code work, I have probelm with filepath
declaration.
---------------------------------------------------
import os, shutil
filepath = ' C:\\Documents and Settings\\060577\\Local
Settings\\Application Data\\Microsoft\\Outlook\\* '
backup = ' D:\\temp\\outlook '
Aside: having a space at the beginning and/or end of the filename has
no good effect and may cause problems, so don't do it.
os.system ("xcopy /s %s %s" % (filepath, backup))
-----------------------------------------
It's always a good idea *before* you write an os.system call on *any*
operating system to try a few sample commands at the command line. You
would find in this case that the problem exists there too -- it has
nothing to do with Python. The problem is that the first argument
*contains* spaces, but the Windows command processor splits the command
line on spaces, so it thinks the first argument is 'C:\\Documents'. On
both the command line and in your script, you will need to wrap quotes
around each argument that does/could contain spaces.

[untested]
os.system ('xcopy /s "%s" "%s"' % (filepath, backup))

Hint: you should find it easier using raw strings for Windows
filenames:
backup = r'D:\temp\outlook'

HTH,
John

Nov 22 '06 #3

P: n/a
Thank You all for reply's so far
<code>
import os, sys
from win32com.shell import shell, shellcon

local_app_data = shell.SHGetSpecialFolderPath (0,
shellcon.CSIDL_LOCAL_APPDATA)
outlook_path = os.path.join (local_app_data, "Microsoft", "Outlook")

print outlook_path

</code)
The above code was fine while printing, when I am trying to use this
(outlook_path) to use as source path it is giving file permission error

can you please clarify this

Nov 22 '06 #4

P: n/a
k.i.n.g. wrote:
[snip code]
The above code was fine while printing, when I am trying to use this
(outlook_path) to use as source path it is giving file permission error
can you please clarify this
Did you follow the link that Fredrik Lundh gave you?

/MiO
Nov 22 '06 #5

P: n/a
Hi ,

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.
--------------------------------------------------------------------------------
start of the code
------------------------------------------------------------------------------------
import os, sys ,shutil, win32file
import time
from win32com.shell import shell, shellcon

local_app_data = shell.SHGetSpecialFolderPath
(0,shellcon.CSIDL_LOCAL_APPDATA)
outlook_path = os.path.join (local_app_data, "Microsoft", "Outlook")

# print outlook_path
#c:\documents and settings\060577\Local Settings\Application
Data\Microsoft\Outlook

source = outlook_path
#source = outlook_path +'\\*'
print source

backup = 'D:\MailBackup'
backup1=r'D:\temp\outlook1'
backup2 = 'D:\MailBackup'
today = backup1 + '_' + time.strftime ( '%Y-%m-%d')
now = time.strftime('%H.%M.%S')
target = today +'_'+ now
if not os.path.exists(target):
os.mkdir(target) # make directory
print 'Successfully created directory', target

#shutil.copy(source, backup)
#os.system( "copy "(source,backup))
#os.system ("xcopy %s %s" % (source, backup1))
#os.system ("xcopy /s %s %s" % (outlook_path, backup1))
#os.system ("xcopy /s %s %s" % (backup2, backup1))
#os.system( 'xcopy /i D:\\MailBackup\\* d:\\temp\\outlook')
#win32file.CopyFile (outlook_path, backup, 0)
#os.system ("xcopy /s %s %s" % (backup,target))

os.system ("xcopy /s %s %s" % (source,target)) # this doesnt give me
any errors but the #work is not done

win32file.CopyFile (source, target, 1)
-----------------------------------------------------------------------
end
------------------------------------------------------------------
---------
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.')

Nov 22 '06 #6

P: n/a
MC
Hi!

" are your friend.

See, also:
filepath = '"%HOMEPATH%\\LocalSettings\\Application
Data\\Microsoft\\Outlook\\*"'

and %USERPROFILE% %APPDATA% etc.

--
@-salutations

Michel Claveau
Nov 22 '06 #7

P: n/a
"MC" wrote:
" are your friend.
to be precise, list2cmdline is your friend. see discussion and examples here:

http://effbot.org/pyfaq/why-can-t-ra...-backslash.htm

</F>

Nov 22 '06 #8

P: n/a
Hi,

The following code has worked for me, I will continue from here to make
this further userfriendly.
More I would like to know how can i distribute my python code as self
installer package.
In the process of learning programming I would like take
OutlookBackup.py as my first project and learn accordingly. Please
guide me in this.

Once again thank you all of you for your valuable suggestions

Regards,
Kk
---------------------------------------------------------------------------------------------------
import os, sys ,shutil, win32file
import time
from win32com.shell import shell, shellcon

local_app_data = shell.SHGetSpecialFolderPath
(0,shellcon.CSIDL_LOCAL_APPDATA)
outlook_path = os.path.join (local_app_data, "Microsoft", "Outlook" )

# print outlook_path
#c:\documents and settings\060577\Local Settings\Application
Data\Microsoft\Outlook

source = outlook_path
#source = outlook_path +'\\*'
#print source

backup = 'D:\MailBackup'
backup1=r'D:\temp\outlook1'
backup2 = 'D:\MailBackup'
today = backup1 + '_' + time.strftime ( '%Y-%m-%d')
now = time.strftime('%H.%M.%S')
target = today +'_'+ now
shutil.copytree(source, target) # copy directory tree

-------------------------------------------------------------------------------------------------------

Nov 23 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.