Results 1 to 5 of 5

Thread: VBScript to VB.NET Conversion

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    14

    VBScript to VB.NET Conversion

    Hello. I've been looking online all over for a VBScript to VB.NET converter, but of course, they are incompatible.

    Could someone rewrite these three into VB.NET for me, please?

    revert_version.vbs
    Code:
    on error resume next
    set fso = createobject("scripting.filesystemobject")
    set shell = createobject("shell.application")
    revision_file = wscript.arguments.item(0)
    revision_folder = fso.getparentfoldername(revision_file)
    fso.movefile revision_file , left(revision_file,len(revision_file)-8)&".zip"
    set zipfile = shell.namespace(left(revision_file,len(revision_file)-8)&".zip")
    set srcfolder = shell.namespace(revision_folder)
    for each item in srcfolder.items
    if (item.type <> "VERSION File") and (item.name <> fso.getfilename(left(revision_file,len(revision_file)-8)&".zip")) then
    if item.isfolder then
    fso.deletefolder(item.path)
    else
    fso.deletefile(item.path)
    end if
    end if
    next
    for each item in zipfile.items
    srcfolder.copyhere item
    next
    fso.movefile left(revision_file,len(revision_file)-8)&".zip" , revision_file
    create_backup.vbs
    Code:
    on error resume next
    set shell = createobject("shell.application")
    set fso = createobject("scripting.filesystemobject")
    newfilename = "__BACKUP_"&replace(cstr(date),"/","_")&" "&replace(cstr(time),":","_")
    set zipfile = fso.createtextfile(wscript.arguments.item(0)&"\"&newfilename&".zip")
    zipfile.write("PK" & chr(5) & chr(6) & string(18,chr(0)))
    zipfile.close
    set zipfile = shell.namespace(wscript.arguments.item(0)&"\"&newfilename&".zip")
    set srcfolder = shell.namespace(wscript.arguments.item(0)&"\")
    for each item in srcfolder.items
    wscript.sleep 500
    if (item.type <> "BACKUP File") and (item.name <> (newfilename&".zip")) then
    zipfile.copyhere item
    end if
    next
    ' the following loop waits until the script has finished adding files to the zip file
    set zipfile2 = fso.getfile(wscript.arguments.item(0)&"\"&newfilename&".zip")
    do
    zipfile2_size = zipfile2.size
    wscript.sleep 100
    loop while zipfile2.size > zipfile2_size
    wscript.sleep 100
    fso.movefile wscript.arguments.item(0)&"\"&newfilename&".zip" , wscript.arguments.item(0)&"\"&newfilename&".backup"
    new_revision.vbs
    Code:
    on error resume next
    set shell = createobject("shell.application")
    set fso = createobject("scripting.filesystemobject")
    newfilename = "__REVISION_"&replace(cstr(date),"/","_")&" "&replace(cstr(time),":","_")
    set zipfile = fso.createtextfile(wscript.arguments.item(0)&"\"&newfilename&".zip")
    zipfile.write("PK" & chr(5) & chr(6) & string(18,chr(0)))
    zipfile.close
    set zipfile = shell.namespace(wscript.arguments.item(0)&"\"&newfilename&".zip")
    set srcfolder = shell.namespace(wscript.arguments.item(0)&"\")
    set zipfile2 = fso.getfile(wscript.arguments.item(0)&"\"&newfilename&".zip")
    wscript.sleep 500
    for each item in srcfolder.items
    wscript.echo item.name
    wscript.sleep 500
    if (item.type <> "VERSION File") and (item.type <> "Compressed (zipped) Folder" ) then
    zipfile.copyhere item
    do
    zipfile2_size = zipfile2.size
    wscript.sleep 100
    loop while zipfile2.size > zipfile2_size
    end if
    next
    ' the following loop waits until the script has finished adding files to the zip file
    wscript.sleep 100
    fso.movefile wscript.arguments.item(0)&"\"&newfilename&".zip" , wscript.arguments.item(0)&"\"&newfilename&".version"
    Thanks.

    I couldn't attach them, because they were not blocked by the filter.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VBScript to VB.NET Conversion

    When I look a request like this one, here's what I see:
    Here's a bunch of code that I'd like you to convert for me. Rather than my making any effort to explain to you what the code does, I'd not only like you to volunteer your time to rewrite the code but I'd also like you spend more time reading the code and working out what it does.
    I like helping others as much as the next man but what I don't like is people taking advantage, either intentionally or not. If you would like total strangers to donate their time to help you then the least you can do is make it as easy as possible for them to do so so that the time they have to donate is as brief as possible. You don't have to but you'll find that a lot of people will simply ignore your request if you don't.

    In my experience, the original code is almost irrelevant because the best VB.NET code to achieve the same result is likely to look completely different. All that matters is the result that you want to achieve so please do us the courtesy of explaining what that is. We can then refer to the original code if necessary but it will then just be a glance or two while we know what we're looking for rather than pouring over code with no existing idea of its purpose.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    14

    Re: VBScript to VB.NET Conversion

    I'm so sorry... I don't understand how this place works too much.

    The first script does the following:
    1. Renames a .version file to a .zip file.
    2. Extracts and merges all directories and files into the same location as the .version file.

    The second script:
    1. Takes all files within the directory that are not .version files and places them in a .zip file that is named the current time and date.
    2. Renames the .zip file to a .version file.

    The third script:
    1. Takes the entire directory and places it in a .zip file.
    2. Renames the .zip file to a .backup file.

    Thank you, and I'm very sorry...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VBScript to VB.NET Conversion

    If you want to zip and unzip files then you have three choices:

    1. If you are using .NET 4.5, which is the latest version and only accessible using VS 2012, then there is ZIP support included in the System.IO.Compression namespace.

    2. You can use a third-party component, e.g. SharpZipLib or DotNetZip. Not all will be free but those two are and they support Framework versions back to 2.0 at least I would think.

    3. You can use the ZIP functionality built into Windows, in which case the VB.NET code will end up looking very similar to that VBScript code.

    Option 3 would be my last resort because it uses unmanaged code but it would probably be the easiest option for you because the code would change very little. You can add a reference to the Microsoft Scripting Runtime from the COM page and then create an instance of the FileSystemObject class in code to be used pretty much as you already are.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VBScript to VB.NET Conversion

    Actually, I missed another option that I always forget because I have never used it. The System.IO.Packaging namespace also includes ZIP support in the shape of the ZipPackage class, which was introduced in .NET 3.0. It was intended for use in deployment scenarios so is not well known but it can be used anywhere. The third-party libraries are easier to use and the new support in System.IO.Compression is much more like them.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width