Solved

vb .net convert to c#

Posted on 2012-03-18
4
242 Views
Last Modified: 2012-03-27
how do we convert this code to c#

  Dim colFiles = Directory.GetFiles("C:\Users\allimages")

        Dim FilePath As String
        Dim FileName As String
        For Each FilePath In colFiles
            Dim intCount As Integer = FilePath.LastIndexOf("\")
            ' Dim intCount2 As Integer = FilePath.LastIndexOf(".")

            FileName = FilePath.Substring(intCount + 1)

            Dim intCount2 As Integer = FileName.IndexOf("_")
            Dim NewName1 As String = FileName.Substring(0, intCount2 + 2) & ".jpg"
            Dim Finalname = "C:\Users\allimages\" & NewName1

            ' If Verify(FileName) Then
            'Dim NewName As String = FilePath.Substring(0, intCount + 1)
            FileSystem.Rename(FilePath, Finalname)
            'End If
        Next
        MsgBox("Done.")

 Public Function Verify(ByVal myFileName As String)
        Dim Pattern As String = "/\d\d_\d\d\./,"
        Dim MyRegex As New Regex(Pattern, RegexOptions.IgnoreCase)
        Return MyRegex.IsMatch(myFileName, 0)
    End Function
0
Comment
Question by:goodluck11
  • 2
4 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 37735980
string[] colFiles;
colFiles = Directory.GetFiles("C:\\Users\\allimages\\", "*.*");
string FilePath = String.Empty;
string FileName = String.Empty;
foreach (FilePath in colFiles) {
    int intCount = FilePath.LastIndexOf("\\");
    //  Dim intCount2 As Integer = FilePath.LastIndexOf(".")
    FileName = FilePath.Substring((intCount + 1));
    int intCount2 = FileName.IndexOf("_");
    string NewName1 = (FileName.Substring(0, (intCount2 + 2)) + ".jpg");
    object Finalname = ("C:\\Users\\allimages\\" + NewName1);
    //  If Verify(FileName) Then
    // Dim NewName As String = FilePath.Substring(0, intCount + 1)
    FileSystem.Rename(FilePath, Finalname);
    // End If
}
MsgBox("Done.");

    
    public void Verify(string myFileName) {
        string Pattern = "/\\d\\d_\\d\\d\\./,";
        Regex MyRegex = new Regex(Pattern, RegexOptions.IgnoreCase);
        return MyRegex.IsMatch(myFileName, 0);
    }

Open in new window


From here: http://www.carlosag.net/tools/codetranslator/
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 37737275
As mentioned in previous ans http://www.carlosag.net/tools/codetranslator/ could be used. At the same time http://www.developerfusion.com/tools/convert/vb-to-csharp/ could be used as well for the conversion.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 37737461
another great online converter is http://converter.telerik.com/
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 37737492
I tried both of those converter tools first but neither could convert the code (after correcting the first line). Only http://www.carlosag.net/tools/codetranslator/ worked (after correcting the first line). First time I ever used the Carlosag converter tool. Weird.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now