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 8 5816
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
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
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
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.')
Hi!
" are your friend.
See, also:
filepath = '"%HOMEPATH%\\LocalSettings\\Application
Data\\Microsoft\\Outlook\\*"'
and %USERPROFILE% %APPDATA% etc.
--
@-salutations
Michel Claveau
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
------------------------------------------------------------------------------------------------------- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bucfan1 |
last post by:
Hello All,
I have been encountering trouble with a SQL Server 2000 Transaction
log file, mainly with the constant growth and lack of the autoshrink
option. Here are the details:
1.) OS is...
|
by: Bing Du |
last post by:
Greetings,
Our former SQL Server 2000 DBA backed up everything in a single disk
file. By everything I mean, full backup, differential backup and
transaction logs. See below for details of how...
|
by: news |
last post by:
Our production database in an exported textfil runs about 60 MB.
Compressed that's about 9 MB.
I'm trying to import the export into another machine running FC3 and
mySQL 11.18, and it appears as...
|
by: Charles Morrall |
last post by:
I have no experience with DB2 as such, but I've been tasked with configuring
backup of a server running DB2 v8 on Windows Server 2003. I do have some
experience with backups in general though. The...
|
by: Bill |
last post by:
I need help closing a CMD window when it is executed from Access.
1) The batch file is called from Access.
2) Access closes,
3) the batch runs a copy of the access database (creating a backup)...
|
by: Dan |
last post by:
Hi,
We have a Windows 2000 network with a couple of Win2k servers. I'm looking
at fault tolerance with regards our Access databases , of which we have a
number of backend mdbs sitting on the...
|
by: rdemyan via AccessMonster.com |
last post by:
Here's my plan for creating nightly backups of the production back-end file
(the IT staff in their infinite wisdom have prevented use of Windows
Scheduler and users do not have administrative...
|
by: elake |
last post by:
I found this thread about a pst file in Windows being locked and I am
having the same issue.
...
|
by: Christian Maslen |
last post by:
Hi All,
I understand in older versions of DB2/UDB this was not possible. The
following article explains how I might do this
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |