February 15, 2011 at 8:41 am
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
February 15, 2011 at 9:35 am
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
February 15, 2011 at 11:25 am
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
February 15, 2011 at 11:47 am
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
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply