Results 1 to 7 of 7

Thread: MAKE A DIR

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208

    Post

    1) How can I MAKE A DIR ??
    2) How can my program check if the dir exist ,
    If not, create the path

    EX:
    want to put someting here:
    c:\program files\project1\DATA\INI\LIST\
    and only this dirrectory exist:
    c:\program files\

    So, I must do that :
    if exist c:\program files\project1\DATA\INI\LIST\ then
    'place my code here
    else
    create c:\program files\project1\DATA\INI\LIST\
    end if




  2. #2
    Guest
    Here you go:

    Code:
    If Dir("C:\program files\", vbDirectory) <> "" Then
    MkDir "C:\program files\project1\DATA\INI\LIST\"
    Else
    Msgbox "Cannot create directory!", vbCritical
    End If
    Or to check if the c:\program files\project1\DATA\INI\LIST\ exists or else create it:

    Code:
    If Dir("C:\program files\project1\DATA\INI\LIST\", vbDirectory) <> "" Then
    MkDir "C:\program files\project1\DATA\INI\LIST\"
    Else
    Msgbox "Cannot create directory!", vbCritical
    End If

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    thank's a lot ..
    I'll try it ..

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    If NOT Dir("C:\program files\project1\DATA\INI\LIST\", vbDirectory) <> "" Then
    MkDir "C:\program files\project1\DATA\INI\LIST\"
    Else
    Msgbox "Cannot create directory!", vbCritical
    End If

    You forgot the If not ..

  5. #5
    Guest
    Nope, it's not needed. The <> is inequality. So, it's like this:

    Code:
    x = Dir("C:\dir\")
    'if it exists, it will return C:\dir
    'if not...it will return nothing ( )
    If x <> "" Then 'If x is not equal to nothing ( )
    MkDir x 'make the directory
    Else 'if it doesn't exist
    Msgbox "Cannot create directory!", vbCritical 
    End If
    If you were to use the code you gave, it'd be:

    Code:
    If NOT Dir("C:\program files\project1\DATA\INI\LIST\", vbDirectory) = "" Then 
    MkDir "C:\program files\project1\DATA\INI\LIST\" 
    Else 
    Msgbox "Cannot create directory!", vbCritical 
    End If

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    I try the 2 code.....
    the first doesn't work so I out a NOT..
    now It's working..
    look:

    Code:
    Private Sub TXT_save_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If Not Dir(TXT_save, vbDirectory) <> "" Then
            If MsgBox("Le directoire :" & vbCrLf & TXT_save & vbCrLf & "n' existe pas ..." & vbCrLf & "Souhaitez-vous le créé ?", vbYesNo, "IRISA") = vbYes Then
                MkDir TXT_save
            Else
               Exit Sub
            End If
        End If
    
        If Not Right$(TXT_save, 1) = "\" Then
            TXT_save = TXT_save & "\"
        End If
    On Error GoTo erreur
    '|||SAVING FILE PATH|||
    End If
    Exit Sub
    erreur:
    MsgBox "Impossible d' écrire !", vbCritical, "IRISA"
    End Sub

  7. #7
    Guest
    Oops, sorry for arguing with you. Didn't even realize it was your thread. Well, as long as it works, that's all that matters.

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