VB to C#

  • Function Main()

    Dim objFSO, objTargetFolder, objFile, colFiles

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objTargetFolder = objFSO.GetFolder(DTSGlobalVariables("gvTargetDirectory").Value &_

    Mid(day(date) + 100, 2,2))

    Set colFiles = objTargetFolder.Files

    If colFiles.Count > 0 Then

    For Each objFile in colFiles

    If DateDiff("d",objFile.DateLastModified, Now) >= 28 Then

    objFile.Delete

    End If

    Next

    End If

  • i think this is the functional equivalent:

    Private Function DoStuff() As Boolean

    Dim s As String

    's = DTSGlobalVariables("gvTargetDirectory").Value

    If Directory.Exists(s) Then

    Dim dinfo As New DirectoryInfo(s)

    For Each objFile As FileInfo In dinfo.GetFiles(s)

    If DateDiff("d", objFile.LastWriteTime, Now) >= 28 Then

    objFile.Delete()

    End If

    Next

    End If

    End Function

    and in C#, by running the vb.NET code through

    http://www.developerfusion.com/tools/convert/vb-to-csharp/

    private bool DoStuff()

    {

    string s = null;

    //s = DTSGlobalVariables("gvTargetDirectory").Value

    if (Directory.Exists(s)) {

    DirectoryInfo dinfo = new DirectoryInfo(s);

    foreach (FileInfo objFile in dinfo.GetFiles(s)) {

    if (DateAndTime.DateDiff("d", objFile.LastWriteTime, DateAndTime.Now) >= 28) {

    objFile.Delete();

    }

    }

    }

    }

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you for your time ..but i have few questions. I am new to scripting, can you explain me regarding the functional equivalent code that u made looking at VB...because i really have lot of scripting work to do. Just say me the steps that i need change for my VB in order to get Functional equivalent....So that i can do my stuff..And thank you

  • ouch that one is not so easy;

    The FileSystemObject is still exists in vb.NET/c#, but there are "better" ways to do it...it's knowing which objects are around, and what they do, that let me make the leap to use FileInfo and DirectoryInfo, instead of the fileSystemObject.

    so much of that difference requires experience from upgrading vb to vb.net, i don't think i can offer you concrete steps that says "do A, B then C."

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply