Results 1 to 6 of 6

Thread: [RESOLVED] Create a folder with unspecified path

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    91

    Resolved [RESOLVED] Create a folder with unspecified path

    Hello VBforums, I was googling / searching the forums for this type of code.
    I want to be able create a folder within my application folder, mainly because I don't want people using my program to use a specified path to be able to use my program.

    Example,
    If I would using a specified path It would be ("C:/Macbrutal/Foldername")
    And the user who would install my application surely, doesn't have macbrutal as username for windows so their path would be ("C:/User/Foldername") and that would bring my program an error, if you get me.

    So to brake it down a little, Let's say my path for my program is ("C:/Macbrutal") I want my program to generate a folder where my application is located (not with specified path) which would be (C:/Macbrutal/newfolder")

    Any ideas?

  2. #2
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: Create a folder with unspecified path

    My.Computer.FileSystem.CreateDirectory(Application.StartupPath & "\foldername")

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,336

    Re: Create a folder with unspecified path

    It's not a good idea to write data to the program folder if you can avoid it because non-administrative users won't have write access. A better option is to use the program data folder, which exists specifically for programs to write data to without regard for user permissions. Like several other special folders, you can get the path using Environment.GetFolderPath or My.Computer.FileSystem.SpecialDirectories. Note that, in several cases, Environment gives the root folder while My gives an application-specific folder.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    91

    Re: Create a folder with unspecified path

    Thank you for the replies!
    It worked like I wanted too, but there's one problem when I use both of the methods and use the Specialdirectories.Programs it takes me to ("C:/Programs") Which is almost good, how can I manually manipulate so the program understands I want to go further ("C:/Programs/NewFolder")?

    I took this code:
    Debug.Print(My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData) and that one made a little too much, that one made a folder (which is great, but with my company name) and then a folder within, which included the version, and then another empty folder.
    And my confusion here is that, I haven't told the program half of what it gave me, how can I be more specific to the program?
    For instance, I want to change the company name it printed to Macbrutal.

    Thanks!
    Last edited by macbrutal; Jul 31st, 2010 at 07:07 AM.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,336

    Re: [RESOLVED] Create a folder with unspecified path

    A folder path is just a string. If you want to extend the path then you just join another string onto it. It can be whatever string you want. As for the company name, you set that in the project properties, by clicking the Assembly Information button on the Application page. You can then do this:
    vb.net Code:
    1. Dim folderPath As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), _
    2.                                            Application.CompanyName)

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    91

    Re: [RESOLVED] Create a folder with unspecified path

    Thank you so much jmcilhinney, now I can finally go to bed!
    Much love / Macbrutal

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