Writing to a separate file in a for loop

Hi,
I have a simple for loop like :
for i := 0; i < len(Item.Url); i++ {
Item.Request[i])
}

I want to write(func) for each [i] to separate files like log_1, log_2, log_3
func WriteResults(filename string, result string) {
f, err := os.Create(filename)
if err != nil {
log.Fatal(err)
return
}
_, err = f.WriteString(result)
if err != nil {
log.Fatal(err)
f.Close()
return
}
err = f.Close()
if err != nil {
log.Fatal(err)
return
}
}

Hi, @devdavid. I think I understand what you want to do, but I don’t understand what your question is. Are you asking how to create file names with an incrementing count? Or how to call the function in the loop? Or something else?

sorry, how call my writing func inside de loop for creating a separate file with inc++.
If I call my writing fuc inside the loop I have only one output file with multiple content.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.