Click here to Skip to main content
15,891,136 members
Articles / Programming Languages / Visual Basic

Synchro

Rate me:
Please Sign up or sign in to vote.
4.43/5 (13 votes)
20 May 2009GPL35 min read 74.4K   1K   75  
A control to synchronize folder contents.
'
' Arguments class: application arguments interpreter
'
' Authors:		R. LOPES
' Contributors:	Hastarin, E. Marcon (VB version)
' Created:		25 October 2002
'
' Version:		1.0
'/

Imports System
Imports System.Collections.Specialized
Imports System.Text.RegularExpressions

Namespace CommandLine.Utility

    Public Class Arguments
        Inherits StringDictionary

        Dim lastName As String = Nothing
        Dim trimChars As Char() = {Chr(34), Chr(39)}
        Public nameValueRegex As New Regex("^([/-]|--){1}(?<name>\w+)([:=])?(?<value>.+)?$", RegexOptions.Compiled)

        Sub New(ByVal args As String())
            ' Constructor
            ' Valid parameters forms:	
            ' {-,/,--}param{ ,=,:}((",')value(",'))	
            ' Examples: -param1 value1 --param2 /param3:"Test-:-work" /param4=happy -param5 '--=nice=--'	
            Dim arg As String
            Dim match As Match
            For Each arg In args
                match = nameValueRegex.Match(arg)
                If match.Success Then
                    lastName = match.Groups("name").Value
                    Add(lastName, match.Groups("value").Value.Trim(trimChars))
                Else
                    ' Found a value (for the last parameter found (space separator))		
                    If Not (lastName Is Nothing) Then
                        ' Matched a name, optionally with inline value	
                        Me.Item(lastName) = arg.Trim(trimChars)
                    End If
                End If
            Next arg
        End Sub

    End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Engineer
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions