so what I am trying to do is: 1) Use a for loop to create a folder within a directory, 2) write the output file to this folder
i am trying to use the value in the for-loop as part of the input2 name and the folder name
import os,re
values = ['alpha','123']
query_file = '/Users/name/Desktop/query.txt' # 'a\nb\nc\nd\n4\n5\n6\n'
reading_file = '/Users/name/Desktop/alpha.txt' #'abcdefghijklmnopqrstuvwxyz'
#reading_file = '/Users/name/Desktop/123.txt' #'123456789'
output_file='/Users/name/Desktop/output.txt'
def func(input1,input2,output):
query=open(input1,'r').read().split('\n')
reading = open(input2,'r').read()
dir,file=os.path.split(input1)
temp_out= os.path.join(dir,output)
out_file=open(temp_out,'w')
for line in query:
m = re.search(line,reading)
if bool(m) == True:
out_file.write( str( m.start() ) +'\n')
print func(query_file,reading_file,output_file)
so it creates a file called output.txt that is in the SAME directory as the input but i want it to (create a folder based on the name) and put the file (within the folder)
right now, i have to do this one at a time and create the folders individually to place the files. . . i would like to use the 'values' list as the 'reading_file' endings (the first one ends in 'alpha' followed by .txt extension, and the second one leads to '123' followed by .txt)
in the end there should be two folders:
'/Users/name/Desktop/alpha/output.txt'
'/Users/name/Desktop/123/output.txt'
*note that the outputs should be different because the inputs should change relative to what is being called in the for loop
i apologize if this is confusing but i'm trying to simplify it as much as possible from what my script is doing. let me know if i need to clarify anything