1

I need to create 3 folders (named as In,Proc,Error) in C:\Ram directory. First I need to check for folder existence in directory. If any of them not present need to create missing folder. If all missed need to create all 3. Could anyone suggest a simple looping code in VB.NET for this requirement .

2
  • We aren't going to do the work for you. At the very least, you should try yourself first, and if unsuccessful, post that code and then we can help you. Commented May 26, 2011 at 14:36
  • Do we also need to check if C:\ram exist? Commented May 26, 2011 at 14:41

1 Answer 1

4
Dim folders = New () { "In", "Proc", "Error" }
For Each folder As String In folders
    Dim dir = Path.Combine("c:\ram", folder)
    If Not Directory.Exists(dir) Then
        Directory.CreateDirectory(dir)
    End If
Next
Sign up to request clarification or add additional context in comments.

2 Comments

Just a thought, is it necessary to check the directory exists, I think the code would work the same without the check.
You don't need to check it. VS will create all folder level for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.