Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ADIR and ASORT for .NET ?
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01020162
Message ID:
01021054
Views:
21
Yuri,
Have you done any testing to find out what part of the code that is "slow". I don't like "old" VB6 functions that you can import in VB.NET so I figured I would write a little code myself to test (again it seems pretty quick but I don't have that many files). Here is the code I used (keep in mind it has no error handling and no error checking (it took me about 10 minutes to write (I got interupted by a phone call <s>)))
private void button6_Click(object sender, System.EventArgs e)
		{
			System.Collections.Specialized.StringCollection myFileCollection = new System.Collections.Specialized.StringCollection();
			string myPath = @"c:\it\";
			string myFileName = "*.*";

			foreach (string myFile in System.IO.Directory.GetFiles(myPath, myFileName))
			{
				myFileCollection.Add(myFile);
			}

			MessageBox.Show(myFileCollection.Count.ToString());

			foreach(string myFile in myFileCollection)
			{
				MessageBox.Show(this.myDataDiff(System.IO.File.GetLastWriteTime(myFile), System.DateTime.Now).ToString());
			}
		

		}

		private long myDataDiff(System.DateTime date1,System.DateTime date2)
		{
			long TicksPerDay = 864000000000;
			long diff = date2.Ticks - date1.Ticks;
			long days = diff/TicksPerDay;

			return days;
		}
Hope this helps.

>>>Einar,
>>>
>>>I need to follow the IT standard for the company, which is VB.NET at the moment. In VB.NET as far as I see, the GetFiles() allows to create a one-dimensional array and with file names only. But I need file dates to sort the list. Am I missing anything here?
>>
>>Yuri,
>>I see. I thought GetFiles() returned a file object and not just a string. You said your current VB.NET code takes several minutes per directory. Could you post your code? Maybe I can find a way to speed it up. Are you using GetLastWriteTime()? It seems pretty snappy to me but then I only have 28 files in the directory I tested :)
>
>Here are two approaches I tested so far:
>
>....
>ofso = CreateObject("Scripting.FileSystemObject")
>.....
>
>Sub CleanBackup(ByVal BackupDirectory)
>        'erase files older than 15 days back
>                If Not ofso.FolderExists(BackupDirectory) Then
>            Exit Sub
>        End If
>        With ofso.GetFolder(BackupDirectory)
>            If .Files.Count > 0 Then
>                For Each oitem In .Files
>                    If DateDiff(DateInterval.Day, oitem.DateCreated, Now) > 14 Then
>                        oitem.delete()
>                    End If
>                Next
>            End If
>        End With
>End Sub
>
>Sub TestCleanBackup(ByVal BackupDirectory)
>        'erase files older than 15 days back
>        If Not System.IO.Directory.Exists(BackupDirectory) Then
>            Exit Sub
>        End If
>
>        Dim aFiles() As String
>
>        aFiles = System.IO.Directory.GetFiles(BackupDirectory, "*.*")
>        For ia = 0 To aFiles.Length - 1
>            If DateDiff(DateInterval.Day, System.IO.File.GetCreationTime(aFiles(ia)), Now) > 14 Then
>                System.IO.File.Delete(aFiles(ia))
>            End If
>        Next
>End Sub
>
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform