Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Can you help me translate this .vbs script to C#

Can you help me translate this .vbs script to C#

Scheduled Pinned Locked Moved C#
csharptoolshelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matjaz xyz
    wrote on last edited by
    #1

    Hi. I was browsing through one of the my companies PCs and found a script which would be usefull to me if it was in C#. I, personaly, dont know much of VB, thats why i ask for you - the experts - to take 5 minutes of your time and translate this little piece of code to C#. Thank you very much in advance!!!!! The code:

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objArgs = WScript.Arguments
    Set folder = fso.GetFolder(objArgs(0))
    Set tifs = folder.Files
    NumberOfFiles = tifs.Count
    ReDim Field(NumberOfFiles)
    i = 0
    For Each file In tifs
    Field(i) = file.Name
    i = i + 1
    If i = NumberOfFiles Then
    Exit For
    End If
    Next
    destination = AddNewFolder(folder.Path, "Hrbtne")
    For i = 0 To NumberOfFiles - 2
    If Right(Field(i), 3) = Right(Field(i+1), 3) Then
    fso.MoveFile folder.Path & "\" & Field(i), destination
    fso.MoveFile folder.Path & "\" & Field(i+1), destination
    End If
    Next
    Erase Field
    EndTime = Timer
    MsgBox "Čas izvajanja " & EndTime - StartTime & " sekund."
    Set fso = Nothing
    Set folder = Nothing
    Set tifs = Nothing

    Function AddNewFolder(path, folderName)
    Dim fso, f, fc, nf
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(path)
    Set fc = f.SubFolders
    Set nf = fc.Add(folderName)
    AddNewFolder = nf.Path & "\"
    End Function

    Regards, Matjaž

    E 1 Reply Last reply
    0
    • M Matjaz xyz

      Hi. I was browsing through one of the my companies PCs and found a script which would be usefull to me if it was in C#. I, personaly, dont know much of VB, thats why i ask for you - the experts - to take 5 minutes of your time and translate this little piece of code to C#. Thank you very much in advance!!!!! The code:

      Set fso = CreateObject("Scripting.FileSystemObject")
      Set objArgs = WScript.Arguments
      Set folder = fso.GetFolder(objArgs(0))
      Set tifs = folder.Files
      NumberOfFiles = tifs.Count
      ReDim Field(NumberOfFiles)
      i = 0
      For Each file In tifs
      Field(i) = file.Name
      i = i + 1
      If i = NumberOfFiles Then
      Exit For
      End If
      Next
      destination = AddNewFolder(folder.Path, "Hrbtne")
      For i = 0 To NumberOfFiles - 2
      If Right(Field(i), 3) = Right(Field(i+1), 3) Then
      fso.MoveFile folder.Path & "\" & Field(i), destination
      fso.MoveFile folder.Path & "\" & Field(i+1), destination
      End If
      Next
      Erase Field
      EndTime = Timer
      MsgBox "Čas izvajanja " & EndTime - StartTime & " sekund."
      Set fso = Nothing
      Set folder = Nothing
      Set tifs = Nothing

      Function AddNewFolder(path, folderName)
      Dim fso, f, fc, nf
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set f = fso.GetFolder(path)
      Set fc = f.SubFolders
      Set nf = fc.Add(folderName)
      AddNewFolder = nf.Path & "\"
      End Function

      Regards, Matjaž

      E Offline
      E Offline
      Expert Coming
      wrote on last edited by
      #2

      If you know C# that really wouldn't be that difficult. Also, this is not quite the right forum for that kind of question. How about you get it as far as you can, and ask for help when you get stuck.

      The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

      M 1 Reply Last reply
      0
      • E Expert Coming

        If you know C# that really wouldn't be that difficult. Also, this is not quite the right forum for that kind of question. How about you get it as far as you can, and ask for help when you get stuck.

        The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

        M Offline
        M Offline
        Matjaz xyz
        wrote on last edited by
        #3

        Umm... yes, VB.Net and C# are pretty similar, but old VB and VBS are not. At least not to me, as i started with C# and am planning to stay around .NET environment. As time is precious, i understand that no help was given really and its ok. I googled a bit, just for kicks, for a VB to C# translator and found a site http://www.carlosag.net/Tools/CodeTranslator/[^] which explained most of the things to me. So, thanks anyway.

        Regards, Matjaž

        L 1 Reply Last reply
        0
        • M Matjaz xyz

          Umm... yes, VB.Net and C# are pretty similar, but old VB and VBS are not. At least not to me, as i started with C# and am planning to stay around .NET environment. As time is precious, i understand that no help was given really and its ok. I googled a bit, just for kicks, for a VB to C# translator and found a site http://www.carlosag.net/Tools/CodeTranslator/[^] which explained most of the things to me. So, thanks anyway.

          Regards, Matjaž

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Thats for VB.Net to C#, VBS, VB6 and under are ENTIRELY different languages, and no one here will convert code like that into .net code. Good luck finding anyone to do pretty much any substantial coding for you around here.

          M 1 Reply Last reply
          0
          • L Lost User

            Thats for VB.Net to C#, VBS, VB6 and under are ENTIRELY different languages, and no one here will convert code like that into .net code. Good luck finding anyone to do pretty much any substantial coding for you around here.

            M Offline
            M Offline
            Matjaz xyz
            wrote on last edited by
            #5

            lol. Thats really a NO!!! Not really a nice message. I just asked for someone to give 5 minutes of his time to me. Nothing big for someone, but for you its like giving your virginity to me. Tough times i gues... Thanks anyway. Like i said... I managed to convert it to C# :P

            Regards, Matjaž

            L 1 Reply Last reply
            0
            • M Matjaz xyz

              lol. Thats really a NO!!! Not really a nice message. I just asked for someone to give 5 minutes of his time to me. Nothing big for someone, but for you its like giving your virginity to me. Tough times i gues... Thanks anyway. Like i said... I managed to convert it to C# :P

              Regards, Matjaž

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Matjaž Grahek wrote:

              Not really a nice message.

              Not really a smart question either.

              Matjaž Grahek wrote:

              I just asked for someone to give 5 minutes of his time to me. Nothing big for someone, but for you its like giving your virginity to me. Tough times i gues...

              Do you know how many people ask for "five minutes" of peoples time around here? It's not like giving away anyone's virginity, it's like I'm giving away five minutes. Read on forum etiquette a bit before you act like an ass.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups