Results 1 to 19 of 19

Thread: Create folder inside Temp folder

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    60

    Exclamation 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 ????

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. My.Computer.FileSystem.CombinePath(My.Computer.FileSystem.SpecialDirectories.Temp, "folder1")
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    60

    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
    Last edited by fokeiro; Jul 14th, 2011 at 06:10 AM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Create folder inside Temp folder

    Quote Originally Posted by fokeiro View Post
    but how can i create a string for this folder1
    I just showed you how.
    Quote Originally Posted by fokeiro View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    60

    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 ?
    Last edited by fokeiro; Jul 14th, 2011 at 06:43 AM.

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Create folder inside Temp folder

    Have a read of the help file, it lists all of the special directories, including this one.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    60

    Re: Create folder inside Temp folder

    i get an error Then

    says ")" expected
    Last edited by fokeiro; Jul 14th, 2011 at 06:51 AM.

  9. #9
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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!

  10. #10

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    60

    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 ?

  11. #11
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    60

    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
    Last edited by fokeiro; Jul 14th, 2011 at 07:14 AM.

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    60

    Re: Create folder inside Temp folder

    cant find the right path >.>
    Last edited by fokeiro; Jul 14th, 2011 at 05:18 PM.

  15. #15

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    60

    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 ?

  16. #16
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Create folder inside Temp folder

    Maybe you should ask that as a different question in its own thread.

  17. #17

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    60

    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

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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"?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    60

    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
    Last edited by fokeiro; Jul 14th, 2011 at 06:19 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width