Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

How to create new constructor?

Code
My.Computer.FileSystem.CreateDirectory("adasd")
        My.Computer.FileSystem.CreateDirectory("afasfas")
        My.Computer.FileSystem.CreateDirectory("dsgdsf")
        My.Computer.FileSystem.CreateDirectory("adasdsasd")
        My.Computer.FileSystem.CreateDirectory("adaaaf")
        My.Computer.FileSystem.CreateDirectory("asdadassd")
        My.Computer.FileSystem.CreateDirectory("gdfsgdfg")
        My.Computer.FileSystem.CreateDirectory("adasfs")
        My.Computer.FileSystem.CreateDirectory("afafssaf")
        My.Computer.FileSystem.CreateDirectory("afsafgsd")

How can I shorten the class length if you understand what I mean.
Dim CreateD() = My.Computer.FileSystem.CreateDirectory(Of String) was the best I could think of but it was incorrect. I don't even know what it's called that I'm trying to do :/
So to create a new directory I would only have to type:
CreateD(folderName)

Any sort of help would be GREATLY appreciated! 😉
Code
for each dir as string in {"ads", "afd", "asopfdj", etc...}
    my.co....createdirectory(dir)
next

?
Do you mean something like this OP?

Code
Public Sub CreateDirectory(ByVal directory As String)
        Try
            My.Computer.FileSystem.CreateDirectory(directory)
        Catch ex As Exception
            Console.WriteLine("Exception thrown while trying to create a directory. Exception message " + ex.Message)
        End Try
    End Sub

Then you would just call it like this:

Code
CreateDirectory("C:\Users\Owner\Desktop\Test\")
(Sep 25, 2016 11:45 AM)My Computer Wrote:  Do you mean something like this OP?

Code
Public Sub CreateDirectory(ByVal directory As String)
        Try
            My.Computer.FileSystem.CreateDirectory(directory)
        Catch ex As Exception
            Console.WriteLine("Exception thrown while trying to create a directory. Exception message " + ex.Message)
        End Try
    End Sub

Then you would just call it like this:

Code
CreateDirectory("C:\Users\Owner\Desktop\Test\")

I thought about it but it wasn't really what I wanted, I must've thought that you could do what I've imagined in some way. Creating a method to make it is the best solution though, cheers mate!
Code
Public Sub CreateDirectory(ParamArray path As String())
    Array.ForEach(path, Sub(p) If Not Directory.Exists(p) Then Directory.CreateDirectory(p))
End Sub

ParamArrays are your friend.

Code
CreateDirectory("C:\Foo1")
CreateDirectory("C:\Foo1", "C:\Foo2")
CreateDirectory("C:\Foo1", "C:\Foo2", "C:\Foo3")
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)

STOP STEALING CODE.

FREE NATHAN

People who report posts are lamers.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by SмℯґƒMay 1, 2020 09:00 PM 2 150 May 1, 2020 09:00 PM
Last Post: 0xDEAD10CC
[C] by A Fresh StartApr 9, 2018 05:12 PM 3 204 Apr 9, 2018 05:12 PM
Last Post: Annabelle Lee
[C#] by TafelpootMar 16, 2016 10:26 AM 13 211 Mar 16, 2016 10:26 AM
Last Post: The-One