panthi
asked on
how to get the file with certain name in a directory which contains many files
I have to open a single file(to read data from it) from a directory which hundreds of files which contains certain character like "new" how to do that ?
FileStream^ fs = File::OpenRead( pathOfIleGoesHere );
ASKER
i need to open the file(from a directory with many files) which contains the name new in the file name? can you please give code example?
directory="c:\test\"
no of files in it are 100 and one of the file name is
"te****_new.csv" how do i pick that up
thanks for your help
directory="c:\test\"
no of files in it are 100 and one of the file name is
"te****_new.csv" how do i pick that up
thanks for your help
Please try:
String^ directory="c:\test\";
array<String^>^files = Directory::GetFiles( directory, "te*_new.csv" ); // or "te????_new.csv", if exactly 4 chars
if (files->Length > 0)
{
FileStream^ fs = File::OpenRead( files[0] );
// read the file here
}
Here is how you can get all the files in a particular directory. You would just need some logic on what to do with the name of the file (i.e. something to compare it to)
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\test"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.