Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

vb .net convert to c#

Posted on 2012-03-18
4
259 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 70

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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