|
-
Aug 17th, 2007, 10:45 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Array problem
Hey guys, I have a method that gets all the file names in a folder that have a certain extension..such as ".env" or whatever. It puts those names in an array which is returned thru the method. I then loop thru this array of file names.
The problem is, if there are only one or two files in the folder it returns nothing. If there are three files it returns one, if there are 4 files it returns two etc..
It seems to not be giving me a correct count.
Here is the code, any help is appreciated!
PHP Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] theFiles;
theFiles = new string[] { };
string lastScan = "3/21/2003 11:12:23 AM";
string path = "C:\\test";
DateTime scan = Convert.ToDateTime(lastScan);
theFiles = GetFilesAfterDate(path, scan);
for (int i = 0; i < theFiles.Length - 1; i++)
{
MessageBox.Show(theFiles[i]);
}//end for
}//end button1_Click
public string[] GetFilesAfterDate(string folder, DateTime date)
{
FileInfo[] files = new DirectoryInfo(folder).GetFiles("*.env");
List<FileInfo> fileList = new List<FileInfo>();
if (files.Length > 0)
{
for (int index = 0; index < files.GetUpperBound(0); index++)
{
if (files[index].LastWriteTime >= date)
{
fileList.Add(files[index]);
}//end if
}//end for
}//end if
string[] filePaths = new string[fileList.Count];
for (int index = 0; index < filePaths.GetUpperBound(0); index++)
{
filePaths[index] = fileList[index].Name;
}//end for
return filePaths;
}//end GetFilesAfterDate
}
}
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|