Solved

vb .net convert to c#

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 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