Does anyone know if it's possible to create an empty folder on the users computer when they install my program?
I want a blank folder created in the app.path location.
Printable View
Does anyone know if it's possible to create an empty folder on the users computer when they install my program?
I want a blank folder created in the app.path location.
I use installshield to write installation applications at work. Installshield offers scripting that will probably be able to do anything you'd need. If you don't have installshield you could always write your own installation program and do whatever you want with it. I'd say go with installshield if you have access to it though.
Just create a blank folder the first time the program is run using MkDir.
P&D sucks!
I believe Visual Studio Installer will this, but I need to double-check this.
I agree with MigetsBro, create it on first run. I assume this is a folder your program needs . . . what if the user deletes the folder? If your program needs this directory then you should always make sure the directory exists before you try to access it to avoid errors.
hmmmm, make sure the directory exists . . . sound like a job for:
VB Code:
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long Private Sub Form_Load() 'make sure "c:\somepath\someotherpath" exists! MakeSureDirectoryPathExists "c:\somepath\someotherpath" End Sub
God I love the Windows API!
That's a freakin' windows API?? ***?! lol. They've thought of everything haven't they...Quote:
Originally posted by Armbruster2
P&D sucks!
I believe Visual Studio Installer will this, but I need to double-check this.
I agree with MigetsBro, create it on first run. I assume this is a folder your program needs . . . what if the user deletes the folder? If your program needs this directory then you should always make sure the directory exists before you try to access it to avoid errors.
hmmmm, make sure the directory exists . . . sound like a job for:
VB Code:
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long Private Sub Form_Load() 'make sure "c:\somepath\someotherpath" exists! MakeSureDirectoryPathExists "c:\somepath\someotherpath" End Sub
God I love the Windows API!
Huh? I know it sounds pretty self explainitory, but what does that api do? Looking at your code I thought it would check to see if the directory exists, and if not, it would make it. Am I not understanding? Sorry, I don't have much api experience.:)
I put your code in my program, however it doesn't do anything that I can see.
Thanks guys. I am going to take your advise and just create the directory in code if it's non-existant.
As for the api... I'm sure it's a great method, but I think it might be a little overkill for my purposes, since I'm not that familiar with api coding, and I can do it easily without an api. :)
This is how I'm going to do it (in the form load).
VB Code:
If Dir$(App.Path & "\files", vbDirectory) <> "files" Then MkDir App.Path & "\files" End If
It "makes sure the directory path exists". If you just need one folder in your app's path, then what you are suggesting will work just fine. If you needed an entire directory structure or several nested folders for your app, then this api call would be a godsend! It will create all the folders at once to make sure the entire path exists, so you could replace . . .Quote:
Originally posted by Cogen
Huh? I know it sounds pretty self explainitory, but what does that api do? Looking at your code I thought it would check to see if the directory exists, and if not, it would make it. Am I not understanding? Sorry, I don't have much api experience.:)
I put your code in my program, however it doesn't do anything that I can see.
VB Code:
If Len(Dir$(App.Path & "\Data", vbDirectory)) = 0 Then MkDir App.Path & "\Data" End If If Len(Dir$(App.Path & "\Data\UserFiles", vbDirectory)) = 0 Then MkDir App.Path & "\Data\UserFiles" End If If Len(Dir$(App.Path & "\Data\UserFiles\Icons", vbDirectory)) = 0 Then MkDir App.Path & "\Data\UserFiles\Icons" End If If Len(Dir$(App.Path & "\Data\UserFiles\Icons\Default", vbDirectory)) = 0 Then MkDir App.Path & "\Data\UserFiles\Icons\Default" End If
with . . .
VB Code:
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long Private Sub Form_Load() 'make sure App.Path & "\Data\UserFiles\Icons\Default" exists! MakeSureDirectoryPathExists App.Path & "\Data\UserFiles\Icons\Default" End Sub
One little hint . . . compliers compare values faster than they compare strings, so . . .
VB Code:
If Len(Dir$(App.Path & "\files", vbDirectory)) = 0 Then MkDir App.Path & "\files" End If
is slightly more efficient.
Also, what if someone puts your app in the root of the drive? Never a good idea, but if they did, app.path would be "C:\" and you would be trying to do . . .
MkDir "C:\\files"
So you can always counter that with . . .
VB Code:
If Len(Dir$(App.Path & "\files", vbDirectory)) = 0 Then If Right$(App.Path, 1) = "\" Then 'user moved my app! MsgBox "Application path is invalid - rerun installation" 'or you could let them use that path and do . . . MkDir App.Path & "files" Else MkDir App.Path & "\files" End If End If
hmm ... I never thought about that. Thanks alot Armbruster2. :)
You are very welcome :)
Good luck with the project