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
Printable View
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
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);
}
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:Note that GetFiles is overloaded and you can also provide a filter to get only certain files.Code:Dim fileNames As String() = IO.Directory.GetFiles("fully qualified folder name here")
jmcilhinney is right. I put up an example oft C code.
I didn't notice the VBNet topic heading : 0