|
-
August 28th, 2005, 08:11 AM
#1
collecting file names
HI i was hoping some one could tell me how to write some code to collect the file names from a folder and place them into an array or list so that they can be compared
thanks
-
August 28th, 2005, 09:41 AM
#2
Re: collecting file names
Code:
CStringArray FileNameArray;
HANDLE hFileFind=NULL; //handle of file found by FindFile function
WIN32_FIND_DATA FileFindData;
int ReturnCode;
hFileFind=FindFirstFile("C:\\MyDirectory\\*.*, &FileFindData); //note \\ is C syntax for a backslash char
if(hFileFind==INVALID_HANDLE_VALUE)
return;
//make sure that only files, and not folders, are put in the list
if((FileFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==0)
FileNameArray.Add(FileFindData.cFileName);
while(TRUE){
ReturnCode = FindNextFile(hFileFind,&FileFindData);
if(ReturnCode==0){ //0 means no more files or some other error
FindClose(hFileFind);
return;
}
//make sure that only files, and not folders, are put in the list
if((FileFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==0)
FileNameArray.Add(FileFindData.cFileName);
}
-
August 28th, 2005, 07:58 PM
#3
Re: collecting file names
I think Hacker2 has provided some overly complex C# code. The System.IO.Directory.GetFiles method returns a string array containing the fully qualified names of all files in the specified folder:
Code:
Dim fileNames As String() = IO.Directory.GetFiles("fully qualified folder name here")
Note that GetFiles is overloaded and you can also provide a filter to get only certain files.
-
August 28th, 2005, 08:13 PM
#4
Re: collecting file names
jmcilhinney is right. I put up an example oft C code.
I didn't notice the VBNet topic heading : 0
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
|