file/folder naming

ecu_jon hayesjdno3 at yahoo.com
Sat Feb 19 05:29:13 CET 2011


im trying to use wxpython to get a source file/files, then a
destination folder to write them to. the file and folder picker works.
the problem is, actually copying (actually shutil.copy2() ). i get an
except error, as if the destination file name is not correct. looking
at the print lines the destination looks right. i used os.path.join to
join the folder path and the filebasename. i can hear it now, that
this belongs on the wxpython page, and i will be posting there as
well. but, im fairly certain its something in this "for files in
sourcepath:"

import wx,os,string,shutil,getpass
from datetime import *

def backupfiles():
    dialog = wx.FileDialog(None, "Choose a source file :", style=1 |
wx.MULTIPLE )
    if dialog.ShowModal() == wx.ID_OK:
        sourcepath = dialog.GetPaths()
    else:
        dialog.Destroy()
    dialog = wx.DirDialog(None, "Choose a destination directory :",
style=1 )
    if dialog.ShowModal() == wx.ID_OK:
        destpath = dialog.GetPath()
    else:
        dialog.Destroy()
    print "sourcepath is :",sourcepath
    print "destpath is :",destpath
    for files in sourcepath:
        print "destpath
is :",os.path.join(destpath,os.path.basename(files))
        try:
            shutil.copy2(sourcepath,
os.path.join(destpath,os.path.basename(files)))
        except:
            print "error file"


class MyForm(wx.Frame):
    """make a frame, inherits wx.Frame"""
    def __init__(self):
        # create a frame, no parent, default to wxID_ANY
        wx.Frame.__init__(self, None, wx.ID_ANY, title="FacBac",
                          pos=(300, 150), size=(500, 200))

        self.SetBackgroundColour("purple")
        panel = wx.Panel(self, wx.ID_ANY)
        self.title1 = wx.StaticText(panel, wx.ID_ANY, "Backup")
        self.title2 = wx.StaticText(panel, wx.ID_ANY, "Restore")

        self.button1 = wx.Button(panel, id=-1, label='Backup ALL')
        self.button1.Bind(wx.EVT_BUTTON, self.button1Click)
        self.button1.SetToolTip(wx.ToolTip("this will backup your
whole folder"))

        gridSizer = wx.GridSizer(rows=4, cols=2, hgap=5, vgap=5)
        gridSizer.Add(self.title1, 0, wx.ALL|wx.ALIGN_CENTER, 5)
        gridSizer.Add(self.title2, 0, wx.ALL|wx.ALIGN_CENTER, 5)
        gridSizer.Add(self.button1, 0, wx.ALL|wx.EXPAND, 5)

        topSizer = wx.BoxSizer(wx.VERTICAL)
        topSizer.Add(gridSizer, 0, wx.ALL|wx.EXPAND, 5)

        self.SetSizeHints(500,200,500,200)

        panel.SetSizer(topSizer)
        topSizer.Fit(self)

    def button1Click(self, event):
        self.button1.SetLabel("Doing Backup")
        backupfiles()
        self.button1.SetLabel("Backup All")

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MyForm().Show()
    #import wx.lib.inspection
    #wx.lib.inspection.InspectionTool().Show()
    app.MainLoop()




More information about the Python-list mailing list