Reputation: 87
I want to create a file named current directory+folder+system date and time. I am getting the output as-
D:\Komal\MyPrograms\Pkg\stemwordwww.yahoo.com42015-03-18 16-31
but I want to store my file named
www.yahoo.com42015-03-18 16-31
in folder stemword
i.e require the output as
D:\Komal\MyPrograms\Pkg\stemword\www.yahoo.com42015-03-18 16-31
Code
def create_file(self,filename,folder):
print 'creating file....'
print 'file is---'
print filename
#Here our filename is url eg-www.amazon.in
dir = os.getcwd()
dir1 = os.path.join(dir,folder)
print 'directory---'
print dir1
date = datetime.datetime.now()
now = date.strftime("%Y-%m-%d %H-%M")
dirPath2 = os.path.join(dir1+filename)
dirPath = dirPath2.rstrip('\n')
filenameCreated = dirPath+now
print 'file is ---'
print filenameCreated
f = self.openfile(filenameCreated + '.txt', 'a')
f.close()
return filenameCreated
Upvotes: 2
Views: 23118
Reputation: 6858
You have an error in this line:
dirPath2 = os.path.join(dir1+filename)
It should be:
dirPath2 = os.path.join(dir1,filename)
Upvotes: 5