Solved

vb .net convert to c#

Posted on 2012-03-18
4
263 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
[X]
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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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