vb.net - Problems creating folders in vb -
I can not create a folder in drive C: Using VB.NET it says, "Access is denied" I Tried a lot of ways but it does not work. I have tried to use this code:
If my.Computer.FileSystem.DirectoryExists ("C: \ log.txt") then the system to use as author. IO.TextWriter = System.IO file. CreateText ("C: \ Log. TTTT") author. Viryline (m and amp; vbCrLf & "top") author. Virline (M. Left and VBCRF & "LRFT") "SA Writer Writer. WrightLine (Me.Width & amp; vbCrLf & amp; "Width") Authors. Use other directory to finish WriteLine (Me.High & amp; vbCrLf & amp; "Height"). CreateDirectory ("C: \ log.txt") Use the system as the author. IoActochrower = System. IOFILE Crete Text ("C: \ Log. TT TT") Writer. Whiteline (100 and VBCRLF) Authors Viraline (100 and VBCRLF) "An author writer (100 & amp; vbCrLf) writer.WriteLine (100 & amp; vbCrLf) ends use if
should I do?
The problem appears that you are getting the concept of directory (i.e. folders) First of all, with files , you see whether a folder named log.txt is present. If it exists, you can use a new name Trying to create a file On the contrary, if the log.txt folder is not present, you create the folder, and then you try to create a file with the same name in the same place. , It is always going to fail, you can not create a file named log.txt , if there is already a folder with the same name in the same place.
I doubt That's what you want to check if Folder C: \ file that folder in For example, something like this:
If My.Computer.FileSystem.DirectoryExists ("C: \") then the author of the system Use. IO.TextWriter = System.IO.File.CreateText ("C: \ log.txt") ... ... Finally use another directory. CreateDirectory ("C: \") Use the system as the author. IO.TextWriter = System.IO.File.CreateText ("C: \ log.txt" ... ... end the end use if
this is definitely a more logical meaning However, in this special case, since C: \ It is a little silly drive, so it will always be present (unless the drive volume is present, in which any folder will fail by making the folder.)
As Plutonics told in the above comments, even if it works you, it is still bad Practice is quite possible, if it is not possible, then the user will not have access to the root of C: drive. This is the separate storage , or system's temporary folder, or user's application data folder, or Somewhere else that is likely to be accessible will be a priority for writing.
Comments
Post a Comment