string to path problem

ecu_jon hayesjdno3 at
Mon Apr 4 05:30:25 CEST 2011

i am writing a basic backup program for my school. so they wanted the
possibility to be able to set source/destination from a config file.
my source/destination was fine before, i would build it up with
functions, like 1 that got the user-name, and put it all together with
os.path.join. but if they set a source in the config file to something
like c:\users\jon\backup  python tries to read from c:\\users\\jon\
\backup, and throws out a read permission (because it doesn't
exist ...). i am not sure what to do at this point. i have look at the
docs for string, and os.____ . i cant os.path.join anything if they
give me an absolute path. here is a bit of the code

import os,string,fnmatch,shutil,time,getpass,md5,ConfigParser
from datetime import *
from os.path import join, getsize

config = ConfigParser.ConfigParser()"config.ini")
source = config.get("myvars", "source")
destination = config.get("myvars", "destination")
helptext = config.get("myvars", "helptext")

def weekChoice():
    dateNum =
    if dateNum <=7:
        week = 1
    elif (dateNum >= 8) and (dateNum <= 14):
        week = 2
    elif (dateNum >= 15) and (dateNum <= 21):
        week = 3
    elif dateNum > 22:
        week = 4
        print "error"
    return week

def destination1():
    global destination
    username = getpass.getuser()
    week = weekChoice()
    weekstr = "week"+str(week)
    destination1 = os.path.join("//mothera","jon","week1") #where //
mothera is a samba server on the network
    return destination1
print "source :",source
destination = destination1()
shutil.copy2(source, destination)

here is some of config.ini

More information about the Python-list mailing list