.net - Create a file from a path, creating subdirectories if they not exists -
.net - Create a file from a path, creating subdirectories if they not exists -
in config of app i've path, illustration "logs\updater\updater.log"
starting app, want create file updater.log, creating subfolders if not exists.
so, if tomorrow user changes path in config "logs\mypathisbetter\updater.log", app continues work, writing log new file.
file.create
, fileinfo.create
, streamwriter.create
or so: that?
or need check if folders exists, before?
i can't find clear reply question on net.
no, don't seem - you'll directorynotfoundexception, believe three.
you need directory.createdirectory(path)
first.
edit:
for bit more of total solution starts path including filename, try:
directory.createdirectory(path.getdirectoryname(fullpath)); textwriter author = new streamwriter(fullpath); writer.writeline("hello mum"); writer.close();
but bear in mind you'll need error handling too, author gets closed (in 'finally' block).
.net file
Comments
Post a Comment