Solved

vb .net convert to c#

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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