change extension and move file, using vb.net -


i have following code, changes extension of txt doc, , moves (from d:\1 d:\2). extension changes successfully, not move, , error

cannot create file when file exists.

please suggest.

for each filepath in directory.getfiles("d:\1", "*.txt")     file.move(filepath, path.changeextension(filepath, ".doc")) next dim filestomove = f in new directoryinfo("d:\1").enumeratefiles("*.doc") each f in filestomove     f.moveto("d:\2") next 

this check existing file of same name , delete first (you may want handle differently). move , rename in 1 call file.move

dim directory1 = "d:\1" dim directory2 = "d:\2" each oldfilename in directory.getfiles(directory1, "*.txt")     dim newfilename = path.changeextension(oldfilename, ".doc").replace(directory1, directory2)     if file.exists(newfilename) file.delete(newfilename)     file.move(oldfilename, newfilename) next 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -