Create folder inside Temp folder
hi got all my embedde resources writing to temp folder and they all works fine but i have the exe that requires the files in a folder example folder1 , my path is
My.Computer.FileSystem.SpecialDirectories.Temp for all the files im using but how can i add
My.Computer.FileSystem.SpecialDirectories.Temp.folder1
to string so it creates the folder and i can write the two files to this one instead of regular temp ????
Re: Create folder inside Temp folder
This:
Code:
My.Computer.FileSystem.SpecialDirectories.Temp.folder1
doesn't make sense. My.Computer.FileSystem.SpecialDirectories.Temp is not itself a folder path. It's a property. My is a namespace. My.Computer is a property is a property of type Microsoft.VisualBasic.Devices.Computer. That Computer object has a FileSystem property that is type Microsoft.VisualBasic.MyServices.FileSystemProxy. That FileSystemProxy object has SpecialDirectories property of type Microsoft.VisualBasic.FileIO.SpecialDirectories. That SpecialDirectories object has a Temp property of type String that returns the path of the temp folder. The String type doesn't have a 'folder1' property.
If you have a String containing the temp folder path and a String containing the name of a subfolder, then what you have is two Strings. How do you usually join two Strings together?
That said, there is a specific mechanism provided for joining partial paths together that allows you to not worry whether they have leading or trailing slashes:
vb.net Code:
My.Computer.FileSystem.CombinePath(My.Computer.FileSystem.SpecialDirectories.Temp, "folder1")
Re: Create folder inside Temp folder
but how can i create a string for this folder1 and how can i create the fodler if it doesnt exist
Re: Create folder inside Temp folder
Quote:
Originally Posted by
fokeiro
but how can i create a string for this folder1
I just showed you how.
Quote:
Originally Posted by
fokeiro
and how can i create the fodler if it doesnt exist
Given that we have already used My.Computer.FileSystem twice, and the name suggests that it does things relating to the file system on your computer, maybe it can create the folder for you. Maybe you should look at what other functionality it provides and see if that includes creating folders.
Re: Create folder inside Temp folder
ok this create the fodler but create a username folder if i sue this path
f (Not System.IO.Directory.Exists("C:\Users\username\AppData\Local\Temp\folder1")) Then
System.IO.Directory.CreateDirectory("C:\Users\username\AppData\Local\Temp\folder1")
C:\Users\username\AppData\Local\Temp\folder1"
but if i use this
C:\Users\myusername\AppData\Local\Temp\folder1"
it doesn't create it
instead of using whoever username is logging in the system
If (Not System.IO.Directory.Exists("C:\Users\myusername\AppData\Local\Temp\folder1")) Then
System.IO.Directory.CreateDirectory("C:\Users\myusername\AppData\Local\Temp\folder1")
My.Computer.FileSystem.CombinePath(My.Computer.FileSystem.SpecialDirectories.Temp, "folder1")
End If
End Sub
my code is like this
Original_Fileset = My.Computer.FileSystem.SpecialDirectories.Temp & "\Original_Filese.set"
Dim writer9 As New IO.FileStream(Original_Fileset, IO.FileMode.Create, IO.FileAccess.Write)
writer9.Write(My.Resources.Original_Fileset, 0, My.Resources.Original_Fileset.Length)
writer9.Close()
then after creating this folder how can i add it to the first line without getting folder1 not in string
how can i assign username to whatever username is using windows ?
Re: Create folder inside Temp folder
Have a read of the help file, it lists all of the special directories, including this one.
Re: Create folder inside Temp folder
"how can i assign username to whatever username is using windows ? " -- You don't... you don't need to. You don't care.
My.Computer.FileSystem.SpecialDirectories.Temp -- this gives you their temp folder.... jmc showed you how to get the temp folder path and add Folder1 to the end of it... all you need to do is assign it to a string, then you can use that to see if the folder exists...
ahhh.... I see what you did... sigh... clearly you didn't look up the documentation... CombinePath just creates a STRING representing the folder path ... it doesn't actually create the folder...
Code:
dim mytempfodler as string = My.Computer.FileSystem.CombinePath(My.Computer.FileSystem.SpecialDirectories.Temp, "folder1")
If (Not System.IO.Directory.Exists(mytempfodler) Then
System.IO.Directory.CreateDirectory(mytempfodler)
End If
make sense?
-tg
Re: Create folder inside Temp folder
i get an error Then
says ")" expected
Re: Create folder inside Temp folder
Please take the time to write and spell check your posts, calm down on the typing speed :).
You have been shown the CreateDirectory method, the CombinePath method, the Directory.Exists method and now the SpecialDirectories, have a go and try it!
Re: Create folder inside Temp folder
lol yeah i get this error
in the word
Then
")" expected
and in what part of my project should i try this in form1_load ?
Re: Create folder inside Temp folder
This is why sometimes I post code that isn't quite right... you're copying and pasting code w/o understanding what you are doing or what the code does. Take your time, debug, and you'll find where the missing ) goes...
-tg
Re: Create folder inside Temp folder
finally figure it out thanks guys a lot !!!
since all my files are coded like this
Original_Fileset = My.Computer.FileSystem.SpecialDirectories.Temp & "\Original_Fileset.set"
Dim writer9 As New IO.FileStream(Original_Fileset, IO.FileMode.Create, IO.FileAccess.Write)
writer9.Write(My.Resources.Original_Fileset, 0, My.Resources.Original_Fileset.Length)
writer9.Close()
can can i make this file write to that folder instead of just temp
Re: Create folder inside Temp folder
Yes you can. You just have to use the path of that folder instead of the path of the temp folder. We've already shown you the "proper" way to do it but, even if you don't understand that, you're already joining a file name onto the temp folder path so what exactly is the problem with joining a folder name?
Re: Create folder inside Temp folder
cant find the right path >.>
Re: Create folder inside Temp folder
all u think that a button can be created than one clicked it shows with drives are connected to which sata ports ??? example
harddrive1 - port EX0000
dvddrive - port FX0000
and on ?
Re: Create folder inside Temp folder
Maybe you should ask that as a different question in its own thread.
Re: Create folder inside Temp folder
ok i will back on topic
i know on this
Original_Fileset = My.Computer.FileSystem.SpecialDirectories.Temp & "\Original_Fileset.set"
Dim writer9 As New IO.FileStream(Original_Fileset, IO.FileMode.Create, IO.FileAccess.Write)
writer9.Write(My.Resources.Original_Fileset, 0, My.Resources.Original_Fileset.Length)
writer9.Close()
this is the path right ?
My.Computer.FileSystem.SpecialDirectories.Temp
how can i add a valid patch to this folder ?
but how i can do the same to the new added folder in temp Folder1
Re: Create folder inside Temp folder
If you can append "\Original_Fileset.set" to the temp folder path, why can't you append "\folder1\Original_Fileset.set"?
Re: Create folder inside Temp folder
nvm thanks for the help figure it out add the write files to the button so folder gets created first