Creating a function for a directory

Matt mattgraves7 at gmail.com
Mon Nov 11 17:26:46 EST 2013


So I want to take the file, "desktop/test.txt" and write it to "desktop/newfolder/test.txt". I tried the below script, and it gave me: "IOError: [Errno 2] No such file or directory: 'desktop/%s.txt'". Any suggestions would be great.



def firstdev(file):
	in_file = open("desktop/%s.txt") % file
	indata = in_file.read()
	out_file = open("desktop/newfolder/%s.txt", 'w') % file
	out_file.write(indata)
	out_file.close()
	in_file.close()
	
firstdev("test")



More information about the Python-list mailing list