Results 1 to 14 of 14

Thread: MkDir,

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    Sorry if it's a stupid question
    But how do I make a folder called FOLDER1 inside a specified directory
    eg. c:\winnt\Folder\Folder1.
    How do I create the Folder1. I know that it's MkDir but I'm not really sure of the syntax

  2. #2
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    It's simply:
    Code:
    MkDir "C:\winnt\Folder\Folder1"
    Hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  3. #3
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335
    If I use
    Code:
    MkDir "C:\NewDir"
    And then use it again, it shows me an error?
    How do I fix it so it can make the dir only the first time I activate my app and since then it won't show that error?

    BTW, I want to keep the folder and not Kill it.
    Any ideas?
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  4. #4
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    You could check to see if it exists first before you try to create it.
    Code:
    If Dir("C:\NewDir",vbDirectory) = "" Then
      'Folder does not exist so create it
      MkDir "C:\NewDir"
    Else
      Msgbox "Directory already exists!"
    End If
    Hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  5. #5
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335
    Yup.
    Does the trick .
    THANX
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    Hi guys
    thanks for the help
    I keep getting an error message for an Invalid outside Procedure when I try this:
    Any ideas
    Code:
    Dim dirname As String, newdir As String
    Dim f As String
    
    dirname = "C:\Test\newFolder\"
    newdir = dirname & "NEWDIR"
    
    MkDir newdir
    newdir = newdir + "\"
    Is it possible to use MkDir in this manner??????

  7. #7
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    Your code works fine, it's just where you are placing it that is the problem. It needs to go into a sub or function which is why you are getting your error.
    Try placing it in an event sub such as:
    Code:
    'place a command button on your form
    Private Sub Command1_Click()
    Dim dirname As String, newdir As String
    Dim f As String
    
    dirname = "C:\Dev\"
    newdir = dirname & "NEWDIR"
    
    MkDir newdir
    newdir = newdir + "\"
    End Sub
    'The code will run when you click Command1
    or place it in a function like:
    Code:
    Private Function MakeFolder(NewDir as String)
    Dim dirname As String
    
    dirname = "C:\Dev\"
    NewDir = dirname & NewDir
    
    MkDir NewDir
    End Function
    and then you could call this function like:
    Code:
    Private Sub Form_Load()
    MakeFolder("NameOfNewDIR")
    End Sub
    Hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    Cheers
    Thanks a lot

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    Hopefully you may be able to help me again.
    Thanks to you guys here's what I now have:
    Code:
    Private Function MakeFolder(NewDir As String)
    Dim dirname As String
    
    dirname = "C:\Test\"
    NewDir = dirname & NewDir
    
    MkDir NewDir
    End Function
    Private Function SearchForFileExt()
    Dim findfiles As String
    findfiles = Dir$(dirname & "*.jpg")
    
    Do While findfiles <> ""
    FileCopy dirname & findfiles, NewDir & findfiles
    findfiles = Dir$
    Loop
    
    End Function
    
    Private Sub Timer1_Timer()
    If Dir("C:\Test\NewFolder", vbDirectory) = "" Then
    MakeFolder ("ArchiveFolder")
    Else
    Call SearchForFileExt
    End If
    End Sub
    What I am trying to do now is put all files that are contained in the folder C:\TEST into the newly created folder C:\TEST\ArchiveFolder.
    Thanks a lot for your time, I really appreciate it
    JK


  10. #10
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi again!!

    Ok.. In your MakeFolder function, you have two variables, NewDir and dirname. These are only local to the function and so when you call the SearchForFileExt function, they dont hold any values unless you say so within that function. There are two ways around it. Either declare the variables in the declarations area of your code or give them values in the function you are using them in.

    Example of the latter:
    Code:
    Private Function SearchForFileExt()
    dim dirname as string 'you have to declare them here again
    dim NewDir as string ' they are only local variables
    dirname ="C:\Test\" 'set the values
    NewDir = "Whateveryouwant" 'for both variables
    Dim findfiles As String
    findfiles = Dir$(dirname & "*.jpg")
    
    Do While findfiles <> ""
    FileCopy dirname & findfiles, NewDir & findfiles
    findfiles = Dir$
    Loop
    
    End Function
    Hopefully, this should work for you.

    Hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    S@NSIS, I really appreciate the time you've taken
    Take Care
    Jk

  12. #12
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849
    if I do a mkDir procedure like this:

    Private Function MakeFolder()
    mkDir "New Folder"
    End Function

    will it create the folder in my app directory?

  13. #13
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    I'm not sure, but to do it properly use:
    Code:
    MkDir App.Path & "\New Folder"
    Hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  14. #14
    Guest
    Turn it into a Sub.

    Code:
    Private Sub MakeFolder(folder) 
    If Dir(folder, vbDirectory) = "" Then
    mkDir App.Path & "\" & folder
    Else
    Exit Sub
    End If
    End Sub 
    
    Usage:
    
    Call MakeFolder("NewFolder")
    App.Path will make it so that it's in your exe's directory.

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