Results 1 to 10 of 10

Thread: P&d

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    20

    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.

  2. #2
    Lively Member Harvester's Avatar
    Join Date
    May 2002
    Location
    God's Country
    Posts
    124

    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.

  3. #3
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Just create a blank folder the first time the program is run using MkDir.
    <removed by admin>

  4. #4
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    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:
    1. Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
    2. Private Sub Form_Load()
    3.     'make sure "c:\somepath\someotherpath" exists!
    4.     MakeSureDirectoryPathExists "c:\somepath\someotherpath"
    5. 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!

  5. #5
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    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:
    1. Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
    2. Private Sub Form_Load()
    3.     'make sure "c:\somepath\someotherpath" exists!
    4.     MakeSureDirectoryPathExists "c:\somepath\someotherpath"
    5. End Sub

    God I love the Windows API!
    That's a freakin' windows API?? ***?! lol. They've thought of everything haven't they...
    <removed by admin>

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    20
    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.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    20
    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:
    1. If Dir$(App.Path & "\files", vbDirectory) <> "files" Then
    2.     MkDir App.Path & "\files"
    3. End If

  8. #8
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    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:
    1. If Len(Dir$(App.Path & "\Data", vbDirectory)) = 0 Then
    2.     MkDir App.Path & "\Data"
    3. End If
    4. If Len(Dir$(App.Path & "\Data\UserFiles", vbDirectory)) = 0 Then
    5.     MkDir App.Path & "\Data\UserFiles"
    6. End If
    7. If Len(Dir$(App.Path & "\Data\UserFiles\Icons", vbDirectory)) = 0 Then
    8.     MkDir App.Path & "\Data\UserFiles\Icons"
    9. End If
    10. If Len(Dir$(App.Path & "\Data\UserFiles\Icons\Default", vbDirectory)) = 0 Then
    11.     MkDir App.Path & "\Data\UserFiles\Icons\Default"
    12. End If

    with . . .

    VB Code:
    1. Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
    2. Private Sub Form_Load()
    3.     'make sure App.Path & "\Data\UserFiles\Icons\Default" exists!
    4.     MakeSureDirectoryPathExists App.Path & "\Data\UserFiles\Icons\Default"
    5. End Sub

    One little hint . . . compliers compare values faster than they compare strings, so . . .

    VB Code:
    1. If Len(Dir$(App.Path & "\files", vbDirectory)) = 0 Then
    2.     MkDir App.Path & "\files"
    3. 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:
    1. If Len(Dir$(App.Path & "\files", vbDirectory)) = 0 Then
    2.     If Right$(App.Path, 1) = "\" Then
    3.         'user moved my app!
    4.         MsgBox "Application path is invalid - rerun installation"
    5.         'or you could let them use that path and do . . .
    6.         MkDir App.Path & "files"
    7.     Else
    8.         MkDir App.Path & "\files"
    9.     End If
    10. 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!

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    20
    hmm ... I never thought about that. Thanks alot Armbruster2.

  10. #10
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    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
  •  



Click Here to Expand Forum to Full Width