-
Jul 30th, 2010, 08:55 PM
#1
Thread Starter
Lively Member
[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?
-
Jul 30th, 2010, 09:16 PM
#2
Fanatic Member
Re: Create a folder with unspecified path
My.Computer.FileSystem.CreateDirectory(Application.StartupPath & "\foldername")
-
Jul 31st, 2010, 12:42 AM
#3
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.
-
Jul 31st, 2010, 06:12 AM
#4
Thread Starter
Lively Member
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.
-
Jul 31st, 2010, 11:23 AM
#5
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:
Dim folderPath As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), _ Application.CompanyName)
-
Jul 31st, 2010, 08:02 PM
#6
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|