|
Thread: P&d
-
Oct 22nd, 2002, 07:57 PM
#1
Thread Starter
Junior Member
P&d
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.
-
Oct 22nd, 2002, 08:01 PM
#2
Lively Member
Installations
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.
-
Oct 22nd, 2002, 08:02 PM
#3
PowerPoster
Just create a blank folder the first time the program is run using MkDir.
-
Oct 22nd, 2002, 09:19 PM
#4
Fanatic Member
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!
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Oct 22nd, 2002, 09:30 PM
#5
PowerPoster
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!
That's a freakin' windows API?? ***?! lol. They've thought of everything haven't they...
-
Oct 23rd, 2002, 12:54 AM
#6
Thread Starter
Junior Member
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.
-
Oct 23rd, 2002, 01:25 AM
#7
Thread Starter
Junior Member
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
-
Oct 23rd, 2002, 08:16 AM
#8
Fanatic Member
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.
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 . . .
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
Last edited by Armbruster; Oct 23rd, 2002 at 08:21 AM.
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Oct 23rd, 2002, 12:23 PM
#9
Thread Starter
Junior Member
hmm ... I never thought about that. Thanks alot Armbruster2.
-
Oct 24th, 2002, 02:11 PM
#10
Fanatic Member
You are very welcome 
Good luck with the project
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
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
|