G
Guest
I try to delete a file in a for each loop. My code checks if the file exists
and if it does, it will delete the file and create a new file with the same
name.
The first time it works perfect, but the second time it gives me a
FileIOException. I want to prevent this from happening. What can i do to make
sure the file isn't in use anymore the second time i try to delete it?
for each dr in table.rows
if file.exist("C:\sample.txt") then
file.delete("C:\sample.txt")
dim sw as new streamwriter("C:\sample.txt")
sw.writeline(MyString)
sw.close
else
dim sw as new streamwriter("C:\sample.txt")
sw.writeline(MyString)
sw.close
end if
and if it does, it will delete the file and create a new file with the same
name.
The first time it works perfect, but the second time it gives me a
FileIOException. I want to prevent this from happening. What can i do to make
sure the file isn't in use anymore the second time i try to delete it?
for each dr in table.rows
if file.exist("C:\sample.txt") then
file.delete("C:\sample.txt")
dim sw as new streamwriter("C:\sample.txt")
sw.writeline(MyString)
sw.close
else
dim sw as new streamwriter("C:\sample.txt")
sw.writeline(MyString)
sw.close
end if