Re: file backup in windows
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-help-im-getting-an-error-in-my-program-what-should-i-do /F -- http://mail.python.org/mailman/listinfo/python-list
RE: file backup in windows
| 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)) | - I suggest you let the system work out most of the filepath for you. Things like Application Data are determined by the Windows Shell as they can change according to Windows version / roaming profile settings and so on. The following code snippet shows how to get the Local Application Data folder. It assumes you have installed the pywin32 extensions from http://pywin32.sf.net 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) 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: file backup in windows
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 -- http://mail.python.org/mailman/listinfo/python-list
RE: file backup in windows
[... snip ...] | --- | 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)) | - ... also, for various ways of copying files around under Windows in Python, see: http://tgolden.sc.sabren.com/python/win32_how_do_i/copy-a-file.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 -- http://mail.python.org/mailman/listinfo/python-list
Re: file backup in windows
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: file backup in windows
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: file backup in windows
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.') -- http://mail.python.org/mailman/listinfo/python-list
RE: file backup in windows
| 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 As others have suggested, please cut-and-paste code and traceback from an interpreter session. Don't make people guess what you've done. My code above doesn't do anything with the path bar printing it, so you've obviously attempted some kind of file operation with it. What have you done? The outlook_path itself is a *folder*, not a file. I didn't write out all of your code; you need to add something to copy the file or files you need. Have you done that? Please provide code and traceback if you still have difficulties. 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 -- http://mail.python.org/mailman/listinfo/python-list
RE: file backup in windows
| 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: file backup in windows
Hi! are your friend. See, also: filepath = '%HOMEPATH%\\LocalSettings\\Application Data\\Microsoft\\Outlook\\*' and %USERPROFILE% %APPDATA% etc. -- @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: file backup in windows
MC wrote: are your friend. to be precise, list2cmdline is your friend. see discussion and examples here: http://effbot.org/pyfaq/why-can-t-raw-strings-r-strings-end-with-a-backslash.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: file backup in windows
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 --- -- http://mail.python.org/mailman/listinfo/python-list