473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

FileInfo[] Array - How the heck do I add to it?

I have a pretty urgent application, but want to try and do it in C# instead of VB6. I need to search subfolders of a selected folder. Inside these subfolders, I want to return the files that have the pattern "*_LOG_*.txt". I keep running into an issue though. I try to declare an array of FileInfo[] type, but the declaration insists I use a constructor that doesn't take 0 arguements. I got around this by placing in a dummy text string "foo.txt". When I attempt to add to the array using the following statement, I get an error:

currentSubDir.GetFiles("*_LOG_*txt").CopyTo(return Array, returnArray.Count());

I thought that if I specify the count, it would add to the end of the array. Can someone help me get unstuck?

The error I get is Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
Jun 12 '10 #1
5 11360
@thomasbihn
I think you are supposed to use Lists instead of Arrays, google it.
Jun 12 '10 #2
Curtis Rutland
3,256 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. List<FileInfo> fileList = currentSubDir.GetFiles("*_LOG_*txt").ToList();
Alternatively:
Expand|Select|Wrap|Line Numbers
  1. FileInfo[] fileArray = currentSubDir.GetFiles("*_LOG_*txt");
I just prefer using Lists to arrays because they're easier to work with (adding and removing, that kind of thing).
Jun 15 '10 #3
Curtis Rutland
3,256 Expert 2GB
Also:

I try to declare an array of FileInfo[] type, but the declaration insists I use a constructor that doesn't take 0 arguements.
How are you declaring your array? The proper way to declare an array is:
Expand|Select|Wrap|Line Numbers
  1. FileInfo[] fileArray = new FileInfo[5];
Replace 5 with the proper size.
Jun 15 '10 #4
Thanks for all the tips. I could've done this app in just a few minutes in VB6, but am an absolute idiot as I try to make the paradigm shift to C#. The problem is that in manufacturing, there is little luxury of time to find a suitable app to slowly develop in C#, so I've decided even when the requirement is urgent, I'm going to try to struggle through doing it in C# :)
Jun 15 '10 #5
Curtis Rutland
3,256 Expert 2GB
No prob. Trust me, it's worth learning. C# is an elegant language compared to any kind of VB, but especially VB6. It's easier if you've had some Java background, but once you get used to it, you'll love it.
Jun 15 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
4
by: Filippo Pandiani | last post by:
Hi there, I have just populated my FileInfo array with files from a folder. Before I display them on a grid, I would like to sort them by Date DESC. What is the easiest way to do so? Filippo.
2
by: John Bowman | last post by:
Hi All, ..NET 1.1... I'm wondering if there is any approach more convenient to get a list of FileInfo objects than the following. For example, if I wanted to get 1 list of all the Exe's and all...
4
by: Peter Afonin | last post by:
Hello, It should be a simple solution to this, I've just never done it and cannot find any information so far. I'm getting an array - the list of the files in the directory: Dim dir As...
1
by: Antonio | last post by:
Good morning, I've the following file system : C: -> HTML -> Aziende -> Azienda_1 -> a.jpg -> Azienda_2 -> a.jpg ... -> Azienda_N -> a.jpg my desire is to create an array of fileinfo...
6
by: Jurgen Oerlemans | last post by:
Hello, I want to make an array of filenames in a directory. I started with the following code: Dim DirInfo As IO.DirectoryInfo = New IO.DirectoryInfo("N:\queues\jurgen\") Dim FileInfo As...
0
by: eBob.com | last post by:
I have an array Dim FileInfo(MaxFiles) As OFI of Structure Structure OFI 'OneFileInfo Dim Displayed As Boolean ... Dim Dirname As String
10
by: Michael Murphy | last post by:
Hi, I have a Windows VB.Net app in which I need to keep files in one folder in sync with files in another folder. I have pasted the code below. Can anyone tell me why I end up with a folder with all...
5
by: Tom P. | last post by:
I am having the following problem: I create a FileSystemWatcher and wait for events. When the event does happen I refresh a FileSystemInfo list and set properties accordingly (IsFile, IsDir,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.